<?php
// +----------------------------------------------------------------------+
// | The CompanyName 星座女神                                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2016, CompanyName 星座女神. All rights reserved.       |
// +----------------------------------------------------------------------+
// | Authors: CompanyName 星座女神.                                       |
// |                                                                      |
// +----------------------------------------------------------------------+
/**
 * @version  2.2
 * @author   guokunsheng
 * @date     2017-07-012
 */
namespace app\astro\controller;
// 星盘记分类
class Totalscore
{
    private $base_data = [];
//    private $sign_score = [];
    private $planet_score = [];
    private $house_score = [];
    public $influence = [];

    private $affect = [
        'venu'=>1,// 金星
        'protect_7'=>0.85,// 7宫主
        'about_protect_7'=>0.8,// 与7宫主相关
        'in_house_7'=>1,// 7宫内
        'phase_7'=>0.9,// 与7宫内非合相
        'protect_5'=>0.85,// 5宫主
        'about_protect_5'=>0.8,// 与5宫主相关
        'in_house_5'=>1,// 5宫内
        'phase_5'=>0.9,// 与5宫内非合相
    ];
    // 各意向表达值 0=>分值 1=>是否计算冲突系数 2=>中文
    private $expression = [
        'planet'=>[
            0=>[
                'tianmi'=>[1,0,'甜蜜'],
                'hemu'=>[1,0,'和睦'],
                'xiuenai'=>[2,0,'秀恩爱'],
                'xingyun'=>[1,0,'幸运'],
            ],
            1=>[
                'rouqing'=>[2,1,'柔情'],
                'qingxuduo'=>[3,1,'情绪多'],
                'duobian'=>[0.8,1,'多变'],
                'bumanzu'=>[3,1,'不满足'],
                'lihun'=>[1,1,'离婚'],
            ],
            2=>[
                'tiaoti'=>[1,1,'挑剔'],
                'jiaoliu'=>[3,0,'交流'],
                'duobian'=>[0.7,1,'多变'],
                'huayanqiaoyu'=>[0.6,1,'花言巧语'],
            ],
            3=>[
                'tianmi'=>[2,0,'甜蜜'],
                'wending'=>[1,0,'稳定'],
                'hemu'=>[3,0,'和睦'],
            ],
            4=>[
                'sanjiaolian'=>[0.9,1,'三角恋'],
                'jiqing'=>[3,0,'激情'],
                'zhengchao'=>[2,1,'争吵'],
                'zhudong'=>[4,0,'主动'],
                'jiandan'=>[3,0,'简单'],
                'baoli'=>[0.9,1,'暴力'],
            ],
            5=>[
                'weileqian'=>[1,1,'为了钱'],
                'taohuaduo'=>[3,1,'桃花多'],
                'yiguolian'=>[1,0,'异国恋'],
                'sanjiaolian'=>[0.7,1,'三角恋'],
                'xingyun'=>[3,0,'幸运'],
            ],
            6=>[
                'anlian'=>[5,0,'暗恋'],
                'beiju'=>[3,1,'被拒'],
                'xingyayi'=>[0.1,1,'性压抑'],
                'xinglengdan'=>[0.1,1,'性冷淡'],
                'fawei'=>[4,1,'乏味'],
                'fuchu'=>[4,1,'付出'],
                'kongzhi'=>[2,1,'控制'],
                'laoshaopei'=>[0.9,0,'老少配'],
                'yinren'=>[3,1,'隐忍'],
                'wending'=>[3,0,'稳定'],
                'weileqian'=>[0.3,1,'为了钱'],
            ],
            7=>[
                'yidi'=>[5,1,'异地'],
                'lihun'=>[1,1,'离婚'],
                'shanhun'=>[2,0,'闪婚'],
                'dushen'=>[0.5,1,'独身'],
                'tongxing'=>[0.1,1,'同性'],
                'baochijuli'=>[6,0,'保持距离'],
                'lenggan'=>[4,0,'冷感'],
                'fanchang'=>[3,1,'反常'],
//                'aishangqipa'=>[2,0,'爱上奇葩'],
            ],
            8=>[
                'cuoai'=>[1.5,1,'错爱'],
                'langman'=>[5,0,'浪漫'],
                'xisheng'=>[0.4,1,'牺牲'],
                'qipain'=>[1,1,'欺骗'],
                'aimei'=>[3,1,'暧昧'],
                'jingshenlianai'=>[3,0,'精神恋爱'],
                'guanxihunluan'=>[2,1,'关系混乱'],
                'chenni'=>[1,1,'沉溺'],
                'kunhuo'=>[2,1,'困惑'],
                'tianmi'=>[1,0,'甜蜜'],
                'sanjiaolian'=>[0.8,1,'三角恋'],
            ],
            9=>[
                'shenqing'=>[2,0,'深情'],
                'jinji'=>[1,1,'禁忌'],
                'jiujie'=>[2,1,'纠结'],
                'baoli'=>[0.8,1,'暴力'],
                'jiduan'=>[1,1,'极端'],
                'kongzhi'=>[3,1,'控制'],
                'xingxiyin'=>[4,0,'性吸引'],
                'sanjiaolian'=>[0.7,1,'三角恋'],
                'zhanyouyu'=>[2,0,'占有欲'],
            ],
        ],
        'sign'=>[
            1=>[
                'jiandan'=>[4,0,'简单'],
            ],
            2=>[
                'wending'=>[3,0,'稳定'],
                'zhanyouyu'=>[3,0,'占有欲'],
                'anlian'=>[1,0,'暗恋'],
            ],
            3=>[
                'jiaoliu'=>[2,0,'交流'],
                'duobian'=>[2,0,'多变'],
                'huayanqiaoyu'=>[1,0,'花言巧语'],
            ],
            4=>[
                'rouqing'=>[4,0,'柔情'],
                'qingxuduo'=>[1,0,'情绪多'],
                'xingyun'=>[0.4,0,'幸运'],
                'anlian'=>[0.5,0,'暗恋'],
            ],
            5=>[
                'xiuenai'=>[3,0,'秀恩爱'],
                'xingyun'=>[1,0,'幸运'],
            ],
            6=>[
                'tiaoti'=>[3,0,'挑剔'],
                'duobian'=>[0.3,0,'多变'],
                'kongzhi'=>[0.2,0,'控制'],
                'fuchu'=>[1,0,'付出'],
                'anlian'=>[2,0,'暗恋'],
            ],
            7=>[
                'tianmi'=>[1,0,'甜蜜'],
                'hemu'=>[1,0,'和睦'],
            ],
            8=>[
                'shenqing'=>[3,0,'深情'],
                'jinji'=>[1,0,'禁忌'],
                'jiujie'=>[1,0,'纠结'],
                'jiduan'=>[1,0,'极端'],
                'kongzhi'=>[2,0,'控制'],
                'xingxiyin'=>[1,0,'性吸引'],
                'sanjiaolian'=>[0.2,0,'三角恋'],
                'wending'=>[1,0,'稳定'],
                'zhanyouyu'=>[3,0,'占有欲'],
            ],
            9=>[
                'yiguolian'=>[1,0,'异国恋'],
                'sanjiaolian'=>[0.6,0,'三角恋'],
                'duobian'=>[0.8,0,'多变'],
            ],
            10=>[
                'laoshaopei'=>[0.2,0,'老少配'],
                'anlian'=>[3,0,'暗恋'],
            ],
            11=>[
                'baochijuli'=>[1,0,'保持距离'],
                'lenggan'=>[1,0,'冷感'],
            ],
            12=>[
                'langman'=>[1,0,'浪漫'],
                'aimei'=>[1,0,'暧昧'],
                'jingshenlianai'=>[1,0,'精神恋爱'],
            ],

        ],
        'house'=>[
            2=>[
                'weileqian'=>[1,0,'为了钱'],
            ],
            3=>[
                'yidi'=>[0.1,0,'异地'],
            ],
            5=>[
                'tianmi'=>[1,0,'甜蜜'],
            ],
            6=>[
                'fuchu'=>[2,0,'付出'],
            ],
            8=>[
                'weileqian'=>[1,0,'为了钱'],
            ],
            9=>[
                'yidi'=>[2,0,'异地'],
                'yiguolian'=>[1,0,'异国恋'],
            ],
            10=>[
                'xingyun'=>[1,0,'幸运'],
            ],
            11=>[
                'xingyun'=>[1.5,0,'幸运'],
            ],
            12=>[
                'aimei'=>[4,0,'暧昧'],
                'anlian'=>[3,0,'暗恋'],
                'jinji'=>[5,0,'禁忌'],
                'jiujie'=>[3,0,'纠结'],
                'chugui'=>[5,0,'出轨'],
                'jingshenlianai'=>[2,0,'精神恋爱'],
            ],
        ],
    ];

    private $mars_expression = [
        'sign'=>[
            1=>[
                'zhengchao'=>[3,0,'争吵'],
                'baoli'=>[1,0,'暴力'],
            ],
            2=>[
                'zhanyouyu'=>[3,0,'占有欲'],
            ],
            3=>[
                'jiaoliu'=>[1,0,'交流'],
                'duobian'=>[1,0,'多变'],
            ],
            4=>[
                'rouqing'=>[1,0,'柔情'],
                'qingxuduo'=>[1,0,'情绪多'],
                'tongxing'=>[1,0,'同性'],
            ],
            5=>[],
            6=>[
                'tiaoti'=>[2,0,'挑剔'],
                'duobian'=>[0.3,0,'多变'],
                'kongzhi'=>[0.2,0,'控制'],
                'fuchu'=>[1,0,'付出'],
                'xinglengdan'=>[0.8,0,'性冷淡'],
            ],
            7=>[
                'hemu'=>[1,0,'和睦'],
            ],
            8=>[
                'kongzhi'=>[2,0,'控制'],
                'xingxiyin'=>[4,0,'性吸引'],
                'wending'=>[1,0,'稳定'],
                'zhanyouyu'=>[3,0,'占有欲'],
                'jiqing'=>[5,0,'激情'],
            ],
            9=>[
                'yiguolian'=>[3,0,'异国恋'],
                'duobian'=>[0.8,0,'多变'],
                'jiqing'=>[1,0,'激情'],
            ],
            10=>[
                'laoshaopei'=>[0.2,0,'老少配'],
            ],
            11=>[
                'tongxing'=>[1,0,'同性'],
            ],
            12=>[
                'guanxihunluan'=>[2,0,'关系混乱'],
                'xingyinyou'=>[2,0,'性引诱'],
            ],
        ],
        'planet'=>[
            2=>[
                'zhengchao'=>[3,1,'争吵'],
            ],
            5=>[
                'jiqing'=>[3,0,'激情'],
            ],
            6=>[
                'xinglengdan'=>[1,0,'性冷淡'],
                'xingyayi'=>[1.5,1,'性压抑'],
                'baoli'=>[0.2,1,'暴力'],
            ],
            7=>[
                'baoli'=>[3,1,'暴力'],
                'tongxing'=>[2,1,'同性'],
            ],
            8=>[
                'guanxihunluan'=>[2,1,'关系混乱'],
                'xingyinyou'=>[2,1,'性引诱'],
                'lihun'=>[0.5,1,'离婚'],
                'tongxing'=>[0.5,1,'同性'],
            ],
            9=>[
                'baoli'=>[3.5,1,'暴力'],
                'jiqing'=>[5,0,'激情'],
            ],
        ],
        'house'=>[
            1=>[
                'zhengchao'=>[1,0,'争吵'],
            ],
            2=>[
                'weileqian'=>[1,0,'为了钱'],
            ],
            3=>[
                'zhengchao'=>[1,0,'争吵'],
            ],
            4=>[
                'zhengchao'=>[1,0,'争吵'],
            ],
            5=>[
                'baoli'=>[1,0,'暴力'],
                'xingxiyin'=>[1,0,'性吸引'],
                'zhudong'=>[2,0,'主动'],
            ],
            7=>[
                'baoli'=>[1,0,'暴力'],
                'zhengchao'=>[3,0,'争吵'],
                'lihun'=>[0.5,0,'离婚'],
            ],
            8=>[
                'jiqing'=>[2,0,'激情'],
                'weileqian'=>[1,0,'为了钱'],
            ],
            9=>[
                'yidi'=>[2,0,'异地'],
                'yiguolian'=>[0.4,0,'异国恋'],
            ],
            12=>[
                'xinglengdan'=>[1,0,'性冷淡'],
                'sanjiaolian'=>[3,0,'三角恋'],
                'lihun'=>[1,0,'离婚'],
            ],
        ],
    ];


    private $moon_expression = [
        'planet'=>[
            0=>[
                'lihun'=>[1,1,'离婚'],
            ],
            4=>[
                'zhengchao'=>[3,1,'争吵'],
                'lihun'=>[0.6,1,'离婚'],
                'baoli'=>[2,1,'暴力'],
            ],
            6=>[
                'fawei'=>[3,1,'乏味'],
            ],
            7=>[
                'yidi'=>[4,1,'异地'],
                'dushen'=>[0.8,1,'独身'],
                'baochijuli'=>[7,0,'保持距离'],
                'lenggan'=>[3,1,'冷感'],

            ],
            8=>[
                'xisheng'=>[0.5,1,'牺牲'],
                'jingshenlianai'=>[2,1,'精神恋爱'],
                'qipian'=>[2,1,'欺骗'],
                'kunhuo'=>[5,1,'困惑'],
                'chenni'=>[2,1,'沉溺'],
            ],
            9=>[
                'kongzhi'=>[3,1,'控制'],
                'baoli'=>[2,1,'暴力'],
            ],
        ],
    ];




    public function __construct($data = [])
    {
        $this->base_data = $data;
//        $this->sign_score = $data['sign_score'];
        if(isset($data['planet_score'])) $this->planet_score = $data['planet_score'];
        if(isset($data['house_score'])) $this->house_score = $data['house_score'];

    }

    public function _initload()
    {
        // 婚恋指数
        $love = $this->getLoveScore();
        // ######################对于某宫，可设该宫成就值=（活跃值+光明值）/2####################
        // 事业指数 =（10宫活跃+10宫光明）/2【大于500则取500】
        $work = ($this->house_score[9]['active'] + $this->house_score[9]['lucky']) /2;
        if($work < 0 ) $work = 0;
        if($work > 500 ) $work = 500;
        // 健康指数 =（500-1宫刑伤）*（500-6宫刑伤）*（500-8宫刑伤）/250000
        $health = (500 - $this->house_score[0]['burn'])
            * (500 - $this->house_score[5]['burn'])
            * (500 - $this->house_score[7]['burn'])/250000;
        if($health < 0 ) $health = 0;
        // 财富指数 =(事业指数+2宫成就值+5宫成就值/2+8宫光明值/2)/3
        $money = (
                $work + ($this->house_score[1]['active'] + $this->house_score[1]['lucky']) / 2
                + ($this->house_score[4]['active'] + $this->house_score[4]['lucky']) / 4
                + $this->house_score[7]['lucky'] /2 )/3;
        if($money < 0 ) $money = 0;
        // 家庭指数 = 4宫成就*（500-太阳刑伤/2）*（500-月亮刑伤）*（500-4宫刑伤）/（500*500*500）
        $home = ($this->house_score[3]['active'] + $this->house_score[3]['lucky']) / 2
            * (500 - $this->planet_score[0]['burn']/2 )
            * (500 - $this->planet_score[1]['burn'])
            * (500 - $this->house_score[3]['burn']) / (500*500*500);
        if($home < 0 ) $home = 0;
        // 学业指数 =（3宫成就值+9宫成就值+水星活跃值）/3
        $study = (($this->house_score[2]['active'] + $this->house_score[2]['lucky']) / 2
                + ($this->house_score[8]['active'] + $this->house_score[8]['lucky']) / 2
                + $this->planet_score[2]['active'])/3;
        if($study < 0 ) $study = 0;

        $ret = [
            'love'=>round($love),
            'work'=>round($work),
            'health'=>round($health),
            'money'=>round($money),
            'home'=>round($home),
            'study'=>round($study),
        ];
        return $ret;
    }

    /**
     * 获取所有影响星  婚恋详情
     * 查找金星、月亮、火星、5/7宫相关的一切星体，称之为 影响星。
     */
    public function get_affect_planet()
    {
        $score_venu = [];
        $venu = $this->about_planet(3);
//        p($venu);
        foreach ($venu['relevancy'] as $k1 => $v)
        {
            foreach ($this->expression['planet'][$k1] as $k2 => $e)
            {
                if($e[1] == 1 && isset($venu['conflict_degree'][$k1])) $sco = $v * $this->affect['venu'] * $e[0];
                else $sco = $v * $this->affect['venu'] * $e[0];

                if(!isset($score_venu[$k2])) $score_venu[$k2] = ['score'=>0,'name'=>$e[2]];
                $score_venu[$k2]['score'] += $sco;
            }
        }
//        p($score_venu);
        // 金星落座
        $venu_in_sign = $this->base_data['planets'][3]['in_sign_id'];
        foreach ($this->expression['sign'][$venu_in_sign] as $k => $sign_exp)
        {
            if(!isset($score_venu[$k])) $score_venu[$k] = ['score'=>0,'name'=>$sign_exp[2]];
            $score_venu[$k]['score'] += $sign_exp[0];
        }
//        p($score_venu);
        // 金星落宫
        $venu_in_house = $this->base_data['planets'][3]['in_house_id'];
        if(isset($this->expression['house'][$venu_in_house]))
        {
            foreach ($this->expression['house'][$venu_in_house] as $k => $house_exp)
            {
                if(!isset($score_venu[$k])) $score_venu[$k] = ['score'=>$house_exp[0],'name'=>$house_exp[2]];
                else $score_venu[$k]['score'] += $house_exp[0];
            }
        }
//        p($score_venu);
        // 5宫主落宫 古占宫主星+现占宫主星
        $house5_in_house = $this->base_data['houses'][5]['protect_ancient_inhouse_id'];
        if(isset($this->expression['house'][$house5_in_house]))
        {
            foreach ($this->expression['house'][$house5_in_house] as $k => $house_exp)
            {
                if(!isset($score_venu[$k])) $score_venu[$k] = ['score'=>$house_exp[0],'name'=>$house_exp[2]];
                else $score_venu[$k]['score'] += $house_exp[0];
            }
        }
        if($this->base_data['houses'][5]['protect_id'] != $this->base_data['houses'][5]['protect_ancient_id'])
        {
            $house5_in_house = $this->base_data['houses'][5]['protect_inhouse_id'];
            if(isset($this->expression['house'][$house5_in_house]))
            {
                foreach ($this->expression['house'][$house5_in_house] as $k => $house_exp)
                {
                    if(!isset($score_venu[$k])) $score_venu[$k] = ['score'=>$house_exp[0],'name'=>$house_exp[2]];
                    else $score_venu[$k]['score'] += $house_exp[0];
                }
            }
        }
        // 7宫主落宫
        $house7_in_house = $this->base_data['houses'][7]['protect_ancient_inhouse_id'];
        if(isset($this->expression['house'][$house7_in_house]))
        {
            foreach ($this->expression['house'][$house7_in_house] as $k => $house_exp)
            {
                if(!isset($score_venu[$k])) $score_venu[$k] = ['score'=>$house_exp[0],'name'=>$house_exp[2]];
                else $score_venu[$k]['score'] += $house_exp[0];
            }
        }
        if($this->base_data['houses'][7]['protect_id'] != $this->base_data['houses'][7]['protect_ancient_id'])
        {
            $house7_in_house = $this->base_data['houses'][7]['protect_inhouse_id'];
            if(isset($this->expression['house'][$house7_in_house]))
            {
                foreach ($this->expression['house'][$house7_in_house] as $k => $house_exp)
                {
                    if(!isset($score_venu[$k])) $score_venu[$k] = ['score'=>$house_exp[0],'name'=>$house_exp[2]];
                    else $score_venu[$k]['score'] += $house_exp[0];
                }
            }
        }


        $moon = $this->about_planet(1);
        //$moon_expression 月亮表达

        foreach ($moon['relevancy'] as $k1=>$v)
        {
            if(isset($this->moon_expression['planet'][$k1]) && !empty($this->moon_expression['planet'][$k1]))
            {
                if($k1 == 0 && (!isset($moon['sun']) || ($moon['sun'] != 90 && $moon['sun'] != 180)))
                {
                    continue;
                }
                foreach ($this->moon_expression['planet'][$k1] as $k2 => $e)
                {
                    if($e[1] == 1 && isset($moon['conflict_degree'][$k1])) $sco = $v * $e[0];
                    else $sco = $v * $e[0];

                    if(!isset($score_venu[$k2])) $score_venu[$k2] = ['score'=>0,'name'=>$e[2]];
                    $score_venu[$k2]['score'] += $sco;
                }
            }
        }
        // 火星表达
        $mars = $this->about_planet(4);
        foreach ($mars['relevancy'] as $k1 => $v)
        {
            if(isset($this->mars_expression['planet'][$k1]) && !empty($this->mars_expression['planet'][$k1]))
            {
                foreach ($this->mars_expression['planet'][$k1] as $k2 => $e)
                {
                    if($e[1] == 1 && isset($mars['conflict_degree'][$k1])) $sco = $v * $e[0];
                    else $sco = $v * $e[0];

                    if(!isset($score_venu[$k2])) $score_venu[$k2] = ['score'=>0,'name'=>$e[2]];
                    $score_venu[$k2]['score'] += $sco;
                }
            }
        }
        // 火星落座
        $mars_in_sign = $this->base_data['planets'][4]['in_sign_id'];
        if(isset($this->mars_expression['sign'][$mars_in_sign])
            && !empty($this->mars_expression['sign'][$mars_in_sign]))
        {
            foreach ($this->mars_expression['sign'][$mars_in_sign] as $k => $sign_exp)
            {
                if(!isset($score_venu[$k])) $score_venu[$k] = ['score'=>0,'name'=>$sign_exp[2]];
                $score_venu[$k]['score'] += $sign_exp[0];
            }
        }
        // 火星落宫
        $mars_in_house = $this->base_data['planets'][4]['in_house_id'];
        if(isset($this->mars_expression['house'][$mars_in_house]))
        {
            foreach ($this->mars_expression['house'][$mars_in_house] as $k => $house_exp)
            {
                if(!isset($score_venu[$k])) $score_venu[$k] = ['score'=>$house_exp[0],'name'=>$house_exp[2]];
                else $score_venu[$k]['score'] += $house_exp[0];
            }
        }
        $house5 = $this->about_house(5);
        foreach ($house5['relevancy'] as $k1 => $v)
        {
            foreach ($this->expression['planet'][$k1] as $k2 => $e)
            {
                if($e[1] == 1 && isset($house5['conflict_degree'][$k1])) $sco = $v * $this->affect['in_house_5'] * $e[0];
                else $sco = $v * $this->affect['venu'] * $e[0];

                if(!isset($score_venu[$k2])) $score_venu[$k2] = ['score'=>0,'name'=>$e[2]];
                $score_venu[$k2]['score'] += $sco;
            }
        }
        $house7 = $this->about_house(7);
        foreach ($house7['relevancy'] as $k1 => $v)
        {
            foreach ($this->expression['planet'][$k1] as $k2 => $e)
            {
                if($e[1] == 1 && isset($house7['conflict_degree'][$k1])) $sco = $v * $this->affect['in_house_7'] * $e[0];
                else $sco = $v * $this->affect['venu'] * $e[0];

                if(!isset($score_venu[$k2])) $score_venu[$k2] = ['score'=>0,'name'=>$e[2]];
                $score_venu[$k2]['score'] += $sco;
            }
        }

        // 7宫内三颗以上（包含三颗）行星，且不是日金水           离婚5
        $house_7 = $this->base_data['houses'][7];
        if($house_7['have_planet_num'] >= 3)
        {
            if($house_7['have_planet_num'] == 3)
            {
                $test = [];
                foreach ($house_7['in_house_area_planet_info'] as $i => $h7)
                {
                    if($h7['id'] < 10) $test[] = $h7['id'];
                }
                sort($test);
                if($test[0] == 0 && $test[1] == 2 && $test[1] == 3)
                {
                    if(!isset($score_venu['lihun'])) $score_venu['lihun'] = ['score'=>0,'name'=>'离婚'];
                    $score_venu['lihun'] -= 5;
                }
            }
            if(!isset($score_venu['lihun'])) $score_venu['lihun'] = ['score'=>0,'name'=>'离婚'];
            $score_venu['lihun']['score'] += 5;
        }
        $sta1 = 0;
        // 1宫与7宫存在对冲                                离婚5
        foreach ($this->base_data['planets'] as $i => $p)
        {
            if($sta1 != 0) continue;
            if(!empty($p['phase']))
            {
                foreach($p['phase'] as $ph)
                {
                    if(($p['in_house_id'] == 1 && $this->base_data['planets'][$ph['id']]['in_house_id'] == 7)
                        || ($p['in_house_id'] == 7 && $this->base_data['planets'][$ph['id']]['in_house_id'] == 1))
                    {
                        $sta1 = 1;
                        if(!isset($score_venu['lihun'])) $score_venu['lihun'] = ['score'=>0,'name'=>'离婚'];
                        $score_venu['lihun']['score'] += 5;
                    }
                }
            }
        }
        // 5宫与11宫存在对冲                               离婚5
        $sta2 = 0;
        foreach ($this->base_data['planets'] as $i => $p)
        {
            if($sta2 != 0) continue;
            if(!empty($p['phase']))
            {
                foreach($p['phase'] as $ph)
                {
                    if(($p['in_house_id'] == 5 && $this->base_data['planets'][$ph['id']]['in_house_id'] == 11)
                        || ($p['in_house_id'] == 11 && $this->base_data['planets'][$ph['id']]['in_house_id'] == 5))
                    {
                        $sta2 = 1;
                        if(!isset($score_venu['lihun'])) $score_venu['lihun'] = ['score'=>0,'name'=>'离婚'];
                        $score_venu['lihun']['score'] += 5;
                    }
                }
            }
        }

        // 金海成相并且  （日、月、金、火）其中之一在处女座且  金星与火星无相位             独身7  精神恋爱5
        if(isset($this->base_data['planets'][3]['phase']['3-8']) && !isset($this->base_data['planets'][3]['phase']['3-4']))
        {
            if($this->base_data['planets'][0]['in_sign_id'] == 6
                || $this->base_data['planets'][1]['in_sign_id'] == 6
                || $this->base_data['planets'][3]['in_sign_id'] == 6
                || $this->base_data['planets'][4]['in_sign_id'] == 6 )
            {
                if(!isset($score_venu['dushen'])) $score_venu['dushen'] = ['score'=>0,'name'=>'独身'];
                $score_venu['dushen']['score'] += 7;
                if(!isset($score_venu['jingshenlianai'])) $score_venu['jingshenlianai'] = ['score'=>0,'name'=>'精神恋爱'];
                $score_venu['jingshenlianai']['score'] += 5;
            }
        }

        // 金星与火海同时成相
        elseif(isset($this->base_data['planets'][3]['phase']['3-8']) && isset($this->base_data['planets'][3]['phase']['3-4']))
        {
            if(!isset($score_venu['jiqing'])) $score_venu['jiqing'] = ['score'=>0,'name'=>'激情'];
            $score_venu['jiqing']['score'] += 3;
            if(!isset($score_venu['guanxihunluan'])) $score_venu['guanxihunluan'] = ['score'=>0,'name'=>'关系混乱'];
            $score_venu['guanxihunluan']['score'] += 2;
        }
        // 金星与火冥同时成相
        elseif(isset($this->base_data['planets'][3]['phase']['3-9']) && in_array($this->base_data['planets'][3]['phase']['3-9']['phase_e'],[90,180])
            && isset($this->base_data['planets'][3]['phase']['3-4']) && in_array($this->base_data['planets'][3]['phase']['3-4']['phase_e'],[90,180]))
        {
            if(!isset($score_venu['zhanyouyu'])) $score_venu['zhanyouyu'] = ['score'=>0,'name'=>'占有欲'];
            $score_venu['zhanyouyu']['score'] += 4;
            if(!isset($score_venu['siquhuolai'])) $score_venu['siquhuolai'] = ['score'=>0,'name'=>'死去活来'];
            $score_venu['siquhuolai']['score'] += 8;
        }
        // 火土成(合刑冲)相  简单 -8   激情 -8  主动-8  性压抑+4
        if(isset($this->base_data['planets'][4]['phase']['4-6']) && in_array($this->base_data['planets'][4]['phase']['4-6']['phase_e'],[0,90,180]))
        {
            if(!isset($score_venu['jiandan'])) $score_venu['jiandan'] = ['score'=>0,'name'=>'独身'];
            $score_venu['jiandan']['score'] -= 8;
            if(!isset($score_venu['jiqing'])) $score_venu['jiqing'] = ['score'=>0,'name'=>'精神恋爱'];
            $score_venu['jiqing']['score'] -= 8;
            if(!isset($score_venu['zhudong'])) $score_venu['zhudong'] = ['score'=>0,'name'=>'独身'];
            $score_venu['zhudong']['score'] -= 8;
            if(!isset($score_venu['xingyayi'])) $score_venu['xingyayi'] = ['score'=>0,'name'=>'精神恋爱'];
            $score_venu['xingyayi']['score'] += 4;
        }
        // 火星在白羊、射手、狮子座且不与土星合刑冲
        elseif((!isset($this->base_data['planets'][4]['phase']['4-6'])
                || !in_array($this->base_data['planets'][4]['phase']['4-6']['phase_e'],[0,90,180]))
            && in_array($this->base_data['planets'][4],[1,5,9]))
        {
            if(!isset($score_venu['zhudong'])) $score_venu['zhudong'] = ['score'=>0,'name'=>'主动'];
            $score_venu['zhudong']['score'] += 2;
            if(!isset($score_venu['anlian'])) $score_venu['anlian'] = ['score'=>0,'name'=>'暗恋'];
            $score_venu['anlian']['score'] -= 5;
        }
        if(($this->base_data['planets'][2]['in_sign_id'] == 10 || isset($this->base_data['planets'][2]['phase']['2-6']))
            && ($this->base_data['planets'][4]['in_sign_id'] == 10 || isset($this->base_data['planets'][4]['phase']['4-6'])))
        {
            if(!isset($score_venu['anlian'])) $score_venu['anlian'] = ['score'=>0,'name'=>'暗恋'];
            $score_venu['anlian']['score'] += 6;
        }
        if($this->base_data['planets'][4]['in_sign_id'] == 11 && in_array($this->base_data['planets'][4]['in_house_id'],[5,7,8]))
        {
            if(!isset($score_venu['tongxing'])) $score_venu['tongxing'] = ['score'=>0,'name'=>'同性'];
            $score_venu['tongxing']['score'] += 1.5;
        }
//        if(($this->base_data['planets'][7]['in_house_id'] == 5
//                && (isset($this->base_data['planets'][7]['phase']['7-4'])
//                && in_array($this->base_data['planets'][7]['phase']['7-4'],[0,90,180])))
//            || ($this->base_data['planets'][4]['in_house_id'] == 5
//                && (isset($this->base_data['planets'][4]['phase']['4-7'])
//                && in_array($this->base_data['planets'][4]['phase']['4-7'],[90,180]))))
//        {
//            if(!isset($score_venu['tongxing'])) $score_venu['tongxing'] = ['score'=>0,'name'=>'同性'];
//            $score_venu['tongxing']['score'] += 4;
//        }
        if(($this->base_data['planets'][0]['in_sign_id'] == 10 || isset($this->base_data['planets'][0]['phase']['0-6']))
            && ($this->base_data['planets'][1]['in_sign_id'] == 10 || isset($this->base_data['planets'][1]['phase']['1-6'])))
        {
            if(!isset($score_venu['anlian'])) $score_venu['anlian'] = ['score'=>0,'name'=>'暗恋'];
            $score_venu['anlian']['score'] += 3;
        }
        if(
            session('userinfo.sex') == 2 && (
                (isset($this->base_data['planets'][3]['phase']['3-6']) && isset($this->base_data['planets'][3]['phase']['3-9']))
                && (in_array($this->base_data['planets'][1]['in_sign_id'],[8,10])
                    || (isset($this->base_data['planets'][1]['phase']['1-6']) || isset($this->base_data['planets'][1]['phase']['1-9']))
                )
            )
        )
        {
            if(!isset($score_venu['kongzhi'])) $score_venu['kongzhi'] = ['score'=>0,'name'=>'控制'];
            $score_venu['kongzhi']['score'] += 3.5;
        }
        if(
            (isset($this->base_data['planets'][4]['phase']['4-6']) && isset($this->base_data['planets'][4]['phase']['4-9']))
            && ( $this->base_data['planets'][3]['in_sign_id'] == 8 ||
                ((isset($this->base_data['planets'][3]['phase']['3-6'])
                        && in_array($this->base_data['planets'][3]['phase']['3-6']['phase_e'],[0,90,180]))
                    || (isset($this->base_data['planets'][3]['phase']['3-9'])
                        && in_array($this->base_data['planets'][3]['phase']['3-9']['phase_e'],[0,90,180]))))
        )
        {
            if(!isset($score_venu['kongzhi'])) $score_venu['kongzhi'] = ['score'=>0,'name'=>'控制'];
            $score_venu['kongzhi']['score'] += 5;
        }

        if(
            !isset($this->base_data['planets'][8]['phase']['8-0']) && !isset($this->base_data['planets'][8]['phase']['8-1'])
            && !isset($this->base_data['planets'][8]['phase']['8-2']) && !isset($this->base_data['planets'][8]['phase']['8-3'])
            && $this->base_data['planets'][0]['in_sign_id'] != 12 && $this->base_data['planets'][1]['in_sign_id'] != 12
            && $this->base_data['planets'][2]['in_sign_id'] != 12 && $this->base_data['planets'][3]['in_sign_id'] != 12
            && $this->base_data['planets'][ASC]['in_sign_id'] != 12
        )
        {
            if(!isset($score_venu['langman'])) $score_venu['langman'] = ['score'=>0,'name'=>'浪漫'];
            $score_venu['langman']['score'] -= 5;
        }

        if(
            (
                ($this->base_data['planets'][0]['in_sign_id'] == 3 || $this->base_data['planets'][1]['in_sign_id'] == 3
                    || $this->base_data['planets'][2]['in_sign_id'] == 3 || $this->base_data['planets'][ASC]['in_sign_id'] == 3 )
                && !isset($this->base_data['planets'][2]['phase']['2-6'])
            ) || (
                isset($this->base_data['planets'][2]['phase']['2-5']) && !isset($this->base_data['planets'][2]['phase']['2-6'])
            )
        )
        {
            if(!isset($score_venu['anlian'])) $score_venu['anlian'] = ['score'=>0,'name'=>'暗恋'];
            $score_venu['anlian']['score'] -= 12;
        }
        // 若太阳在双鱼座且与海王成相，或，月亮在双鱼且与海王成相
        if(
            ($this->base_data['planets'][0]['in_sign_id'] ==12 && isset($this->base_data['planets'][0]['phase']['0-8']))
            || ($this->base_data['planets'][1]['in_sign_id'] ==12 && isset($this->base_data['planets'][1]['phase']['1-8']))
        )
        {
            if($this->base_data['planets'][8]['in_house_id'] == 5 || $this->base_data['planets'][8]['in_house_id'] == 7)
            {
                if(isset($this->base_data['planets'][8]['phase']['8-6']) && $this->base_data['planets'][8]['phase']['8-6']['phase_e'] == 0)
                {
                    if(!isset($score_venu['fawei'])) $score_venu['fawei'] = ['score'=>0,'name'=>'乏味'];
                    $score_venu['fawei']['score'] -= 6;
                    if(!isset($score_venu['yinren'])) $score_venu['yinren'] = ['score'=>0,'name'=>'隐忍'];
                    $score_venu['yinren']['score'] -= 6;
                    if(!isset($score_venu['wending'])) $score_venu['wending'] = ['score'=>0,'name'=>'稳定'];
                    $score_venu['wending']['score'] -= 6;
                    if(!isset($score_venu['langman'])) $score_venu['langman'] = ['score'=>0,'name'=>'浪漫'];
                    $score_venu['langman']['score'] += 3;
                }
            }
        }

        if(in_array($this->base_data['planets'][0]['in_sign_id'],[2,7,12])
            && in_array($this->base_data['planets'][1]['in_sign_id'],[2,7,12])
            && in_array($this->base_data['planets'][3]['in_sign_id'],[2,7,12]))
        {
            if(!isset($score_venu['fuchu'])) $score_venu['fuchu'] = ['score'=>0,'name'=>'付出'];
            $score_venu['fuchu']['score'] -= 7;
        }
        $true_num = 0;
        $add = 0;
        for($i = 0;$i<5;$i++)
        {
            if($i == 2) continue;
            if(
                $this->base_data['planets'][$i]['in_sign_id'] == 11
                || isset($this->base_data['planets'][$i]['phase'][$i.'-7'])
                || $this->base_data['planets'][$i]['in_sign_id'] == 12
                || isset($this->base_data['planets'][$i]['phase'][$i.'-8'])
            )
            {
                $true_num += 1;
                $add+=1;
            }
        }
        if($true_num == 4)
        {
            if(!isset($score_venu['tongxing'])) $score_venu['tongxing'] = ['score'=>0,'name'=>'同性'];
            $score_venu['tongxing']['score'] += $add;
            if($this->base_data['planets'][7]['in_house_id'] == 5 || $this->base_data['houses'][5]['in_sign_id'] == 11)
            {
                $score_venu['tongxing']['score'] += 4;
            }
            if($this->base_data['planets'][7]['in_house_id'] == 7 || $this->base_data['houses'][7]['in_sign_id'] == 11)
            {
                $score_venu['tongxing']['score'] += 4;
            }
            if(
                isset($this->base_data['planets'][7]['phase']['7-4'])
                && in_array($this->base_data['planets'][7]['phase']['7-4']['phase_e'],[90.180])
                && in_array($this->base_data['planets'][4]['in_house_id'],[5,7,8])
            )
            {
                $score_venu['tongxing']['score'] += 4;
            }
        }
        // 火星与土天海之二成相，命主与土天海之二成相，5宫主（古）与土天海之二成相
        $mars_phase_678_num = 0;
        if(isset($this->base_data['planets'][4]['phase']['4-6'])) $mars_phase_678_num++;
        if(isset($this->base_data['planets'][4]['phase']['4-7'])) $mars_phase_678_num++;
        if(isset($this->base_data['planets'][4]['phase']['4-8'])) $mars_phase_678_num++;
        $house1_pro = $this->base_data['houses'][1]['protect_id'];
        $house1_pro_a = $this->base_data['houses'][1]['protect_ancient_id'];
        $house1_pro_phase_678_num = 0;
        if(isset($this->base_data['planets'][$house1_pro]['phase'][$house1_pro.'-6'])) $house1_pro_phase_678_num++;
        if(isset($this->base_data['planets'][$house1_pro]['phase'][$house1_pro.'-7'])) $house1_pro_phase_678_num++;
        if(isset($this->base_data['planets'][$house1_pro]['phase'][$house1_pro.'-8'])) $house1_pro_phase_678_num++;
        $house1_pro_a_phase_678_num = 0;
        if(isset($this->base_data['planets'][$house1_pro_a]['phase'][$house1_pro_a.'-6'])) $house1_pro_a_phase_678_num++;
        if(isset($this->base_data['planets'][$house1_pro_a]['phase'][$house1_pro_a.'-7'])) $house1_pro_a_phase_678_num++;
        if(isset($this->base_data['planets'][$house1_pro_a]['phase'][$house1_pro_a.'-8'])) $house1_pro_a_phase_678_num++;

        $house5_pro_a = $this->base_data['houses'][5]['protect_ancient_id'];
        $house5_pro_a_phase_678_num = 0;
        if(isset($this->base_data['planets'][$house5_pro_a]['phase'][$house5_pro_a.'-6'])) $house5_pro_a_phase_678_num++;
        if(isset($this->base_data['planets'][$house5_pro_a]['phase'][$house5_pro_a.'-7'])) $house5_pro_a_phase_678_num++;
        if(isset($this->base_data['planets'][$house5_pro_a]['phase'][$house5_pro_a.'-8'])) $house5_pro_a_phase_678_num++;
        if($mars_phase_678_num == 2 && ($house1_pro_phase_678_num == 2 || $house1_pro_a_phase_678_num ==2) && $house5_pro_a_phase_678_num == 2)
        {
            if(!isset($score_venu['tongxing'])) $score_venu['tongxing'] = ['score'=>0,'name'=>'同性'];
            $score_venu['tongxing']['score'] += 5;
        }


        if(session('userinfo.sex') == 1)
        {
            if(
                $this->base_data['planets'][0]['in_sign_id'] %2 == 0
                && $this->base_data['planets'][1]['in_sign_id'] %2 == 0
                && $this->base_data['planets'][ASC]['in_sign_id'] %2 == 0
                && $this->base_data['planets'][3]['in_sign_id'] %2 == 0
                && $this->base_data['planets'][4]['in_sign_id'] %2 == 0

            )
            {
                if(!isset($score_venu['tongxing'])) $score_venu['tongxing'] = ['score'=>0,'name'=>'同性'];
                $score_venu['tongxing']['score'] += 5;
            }
        }
        elseif(session('userinfo.sex') == 2)
        {
            if(
                $this->base_data['planets'][0]['in_sign_id'] %2 == 1
                && $this->base_data['planets'][1]['in_sign_id'] %2 == 1
                && $this->base_data['planets'][ASC]['in_sign_id'] %2 == 1
                && $this->base_data['planets'][3]['in_sign_id'] %2 == 1
                && $this->base_data['planets'][4]['in_sign_id'] %2 == 1

            )
            {
                if(!isset($score_venu['tongxing'])) $score_venu['tongxing'] = ['score'=>0,'name'=>'同性'];
                $score_venu['tongxing']['score'] += 5;
            }
        }
        if($this->base_data['planet_power'][9]['active'])
        {
            if(!isset($score_venu['tongxing'])) $score_venu['tongxing'] = ['score'=>0,'name'=>'同性'];
            $score_venu['tongxing']['score'] += 4;
        }
        // 水瓶7宫。天王落5宫或落整宫制5宫 金火合 且金海 刑冲 【同性+5】
        if($this->base_data['houses'][7]['in_sign_id'] == 11
            && $this->base_data['planets'][7]['in_house_id'] == 5
            && (
                isset($this->base_data['planets'][3]['phase']['3-4'])
                && $this->base_data['planets'][3]['phase']['3-4']['phase_e'] == 0
            )
            && (
                isset($this->base_data['planets'][3]['phase']['3-8'])
                && in_array($this->base_data['planets'][3]['phase']['3-8']['phase_e'],[90,180])
            )
        )
        {
            if(!isset($score_venu['tongxing'])) $score_venu['tongxing'] = ['score'=>0,'name'=>'同性'];
            $score_venu['tongxing']['score'] += 5;
            // 若此时，海王5宫+2
            if($this->base_data['planets'][8]['in_house_id'] == 5)
            {
                $score_venu['tongxing']['score'] += 2;
                // 若天王与与5宫主成相+1
                if(isset($this->base_data['planets'][7]['phase']['7-'.$this->base_data['houses'][5]]['protect_id'])
                    || isset($this->base_data['planets'][7]['phase']['7-'.$this->base_data['houses'][5]]['protect_ancient_id']))
                {
                    $score_venu['tongxing']['score'] += 1;
                    // 若此时，金星落处女、水瓶、双鱼、天蝎+2
                    if(in_array($this->base_data['planets'][3]['in_sign_id'],[6,8,11,12]))
                    {
                        $score_venu['tongxing']['score'] += 2;
                    }
                }
            }

        }
//        p($this->base_data['planet_power']);
//        升双子或水星双子或水木成相，若日月不在摩羯天蝎且不与土星成相，且太阳不在12宫、8宫，【秀恩爱+3】；若此时日金合【秀恩爱+3】；金狮子【秀恩爱+3】；月狮子【秀恩爱+4】；水狮子【秀恩爱+2】
        if($this->base_data['planets'][ASC]['in_sign_id'] == 3
            || $this->base_data['planets'][2]['in_sign_id'] == 3 || isset($this->base_data['planets'][2]['phase']['2-5']))
        {
            if(
                !in_array($this->base_data['planets'][0]['in_sign_id'],[8,10]) && !in_array($this->base_data['planets'][1]['in_sign_id'],[8,10])
//                && !isset($this->base_data['planets'][0]['phase']['0-6']) && !isset($this->base_data['planets'][1]['phase']['1-6'])
            )
            {
                if(!in_array($this->base_data['planets'][0]['in_house_id'],[8,12]))
                {
                    if(!isset($score_venu['xiuenai'])) $score_venu['xiuenai'] = ['score'=>0,'name'=>'秀恩爱'];
                    $score_venu['xiuenai']['score'] += 3;
                    if(isset($this->base_data['planets'][0]['phase']['0-3']) && $this->base_data['planets'][0]['phase']['0-3']['phase_e'] == 0)
                    {
                        $score_venu['xiuenai']['score'] += 3;
                    }
                    if($this->base_data['planets'][3]['in_sign_id'] == 5)
                    {
                        $score_venu['xiuenai']['score'] += 3;
                    }
                    if($this->base_data['planets'][1]['in_sign_id'] == 5)
                    {
                        $score_venu['xiuenai']['score'] += 4;
                    }
                    if($this->base_data['planets'][2]['in_sign_id'] == 5)
                    {
                        $score_venu['xiuenai']['score'] += 2;
                    }
                }
            }
        }


        // 吸渣
        if(session('userinfo.sex') == 2)
        {
            if(!isset($score_venu['xizhatizhi'])) $score_venu['xizhatizhi'] = ['score'=>0,'name'=>'吸渣体质'];
            if($this->base_data['planets'][4]['in_house_id'] == 8 || $this->base_data['planets'][4]['in_house_id'] == 12)
            {
                $score_venu['xizhatizhi']['score'] += 3;
            }
            if($this->base_data['planets'][4]['in_sign_id'] == 8)
            {
                $score_venu['xizhatizhi']['score'] += 2;
            }
            if($this->base_data['planets'][3]['in_sign_id'] == 8)
            {
                $score_venu['xizhatizhi']['score'] += 1;
            }
            if($this->base_data['planets'][9]['in_house_id'] == 5 || $this->base_data['planets'][9]['in_house_id'] == 7)
            {
                $score_venu['xizhatizhi']['score'] += 2;
            }
            if(isset($this->base_data['planets'][3]['phase']['3-9']))
            {
                $score_venu['xizhatizhi']['score'] += 2;
            }
            if(isset($this->base_data['planets'][4]['phase']['4-9']))
            {
                if(in_array($this->base_data['planets'][4]['phase']['4-9']['phase_e'],[60,120])) $score_venu['xizhatizhi']['score'] += 2;
                if(in_array($this->base_data['planets'][4]['phase']['4-9']['phase_e'],[0,90,180])) $score_venu['xizhatizhi']['score'] += 4;
                if(isset($this->base_data['planets'][4]['phase']['4-3'])) $score_venu['xizhatizhi']['score'] += 1;
                if(isset($this->base_data['planets'][4]['phase']['4-5'])) $score_venu['xizhatizhi']['score'] += 1;
                if(isset($this->base_data['planets'][4]['phase']['4-7'])) $score_venu['xizhatizhi']['score'] += 1;
                if(isset($this->base_data['planets'][4]['phase']['4-8'])) $score_venu['xizhatizhi']['score'] += 1;
            }
        }





        $influence = [];
        // 计算影响最大的三颗星 金星 5宫  7宫
        foreach ($venu['relevancy'] as $kr1=> $r1)
        {
            $influence[$kr1] = $r1;
            foreach ($house5['relevancy'] as $kr2=> $r2)
            {
                if(!isset($influence[$kr2])) $influence[$kr2] = $r2;
                else $influence[$kr2] += $r2;
            }
            foreach ($house7['relevancy'] as $kr3=> $r3)
            {
                if(!isset($influence[$kr3])) $influence[$kr3] = $r3;
                else $influence[$kr3] += $r3;
            }
        }
        arsort($influence);
//        p($influence);
//        p($venu);
//        p($house5);
//        p($house7);
//        p($moon);
//        p($mars);
//        p($score_venu);
        $foreach_num = 1;
        foreach ($influence as $kk1 => $ii)
        {
            if($foreach_num > 3) continue;
            $this->influence[] = $kk1;
            $foreach_num++;
        }

        $max_score = 1;
        $new = [];
        foreach ($score_venu as $i => $s)
        {
            if ($s['score'] > $max_score) $max_score = $s['score'];
            if($s['score'] > 1)
            {
                $s['name_e'] = $i;
                $new[] = $s;
            }
        }
        $max_score += 2;// 最大值 +2 作分母
        for ($i=0;$i<count($new);$i++)
        {
            for ($j=$i+1;$j<count($new);$j++)
            {
                if(!isset($new[$i]['content'])) $new[$i]['content'] = $this->getTheContent($new[$i]['name_e'],$new[$j]['name']);
                if(!isset($new[$i]['percent'])) $new[$i]['percent'] = $new[$i]['score']/$max_score;
                if(!isset($new[$i]['percent_cn'])) $new[$i]['percent_cn'] = round($new[$i]['score']/$max_score*100,2).'%';
                if(!isset($new[$j]['content'])) $new[$j]['content'] = $this->getTheContent($new[$j]['name_e'],$new[$j]['name']);
                if(!isset($new[$j]['percent'])) $new[$j]['percent'] = $new[$j]['score']/$max_score;
                if(!isset($new[$j]['percent_cn'])) $new[$j]['percent_cn'] = round($new[$j]['score']/$max_score*100,2).'%';
                if($new[$i]['score'] < $new[$j]['score'])
                {
                    $temp = $new[$i];
                    $new[$i] = $new[$j];
                    $new[$j] = $temp;
                }
            }
        }
//        p($new);
        return $new;
    }


    protected function getTheContent($name = null,$or = '')
    {
        $planets = $this->base_data['planets'];

        $content = $or;
        switch ($name)
        {
            case 'wending':
                $content = '懒得换人就稳定了';
                if($planets[6]['in_house_id'] == 5 || $planets[6]['in_house_id'] == 7
                    || (isset($planets[3]['phase']['3-6']) &&  in_array($planets[3]['phase']['3-6']['phase_e'],[0,90,180])))
                {
                    $content = '稳定是忍耐的结果';
                }
                break;
            case 'jiandan':
                $content = '简简单单是真爱';
                if(isset($planets[3]['phase']['3-6']))
                {
                    $content = '渴望简单';
                }
                break;
            case 'taohuaduo':
                $content = '魅力强桃花旺';
                if((isset($planets[3]['phase']['3-5']) && $planets[3]['phase']['3-5']['phase_e'] == 90) || $planets[3]['in_sign_id'] == 8
                    || $planets[3]['in_house_id'] == 8 || $planets[3]['in_house_id'] == 12)
                {
                    $content = '招蜂引蝶烂桃花';
                }
                break;
            case 'anlian':
                $content = '害怕拒绝不敢说';
                if((!isset($planets[3]['phase']['3-6']) || !in_array($planets[3]['phase']['3-6']['phase_e'],[90,180]))
                    || isset($planets[3]['phase']['3-8']) || isset($planets[1]['phase']['1-8']))
                {
                    $content = '默默喜欢就好';
                }
                break;
            case 'baochijuli':
                $content = '需要独立空间';
                if($planets[ASC]['in_sign_id'] %4 != 0 && $planets[0]['in_sign_id'] %4 != 0
                    && $planets[1]['in_sign_id'] %4 != 0 && $planets[3]['in_sign_id'] %4 != 0)
                {
                    $content = '太亲密会不自在';
                }
                elseif($planets[4]['in_sign_id'] == 10 || $planets[4]['in_sign_id'] == 6 || isset($planets[4]['phase']['4-6']))
                {
                    $content = '烂桃花滚远点';
                }
                break;
            case 'yidi':
                $content = '聚少离多';
                if($planets[3]['in_house_id'] > 6)
                {
                    $content = '两地分居的命';
                }
                break;
            case 'xingyayi':
                $content = '床事不和谐';
                if(isset($planets[4]['phase']['4-6']) && isset($planets[4]['phase']['4-9'])
                    && (in_array($planets[4]['in_house_id'],[8,12]) || in_array($planets[3]['in_house_id'],[8,12])
                        || in_array($planets[1]['in_house_id'],[8,12])))
                {
                    $content = '对性有阴影';
                }
                elseif(isset($planets[4]['phase']['4-6']) && in_array($planets[4]['phase']['4-6']['phase_e'],[0,90,180]))
                {
                    $content = '从性压抑到性冷淡';
                }
                break;
            case 'xingyun':
                $content = '爱情带给你收获';
                $protect_7 = $this->base_data['houses'][7]['protect_id'];
                if(session('userinfo.sex') == 2
                    && (isset($planets[0]['phase']['0-5']) || in_array($planets[0]['in_sign_id'],[9,12])
                        || isset($planets[4]['phase']['4-5']) || in_array($planets[4]['in_sign_id'],[9,12]))
                    && (in_array($planets[3]['in_house_id'],[7,8]) || $protect_7 == 5 || isset($planets[$protect_7]['phase'][$protect_7.'-5'])))
                {
                    $content = '传说中的旺夫相';
                }
                break;
            case 'fuchu':
                $content = '默默付出';
                if($planets[3]['in_sign_id'] == 10)
                {
                    $content = '当牛做马';
                }
                break;
            case 'weileqian':
                $content = '就想找个有钱人';
                break;
            case 'tiaoti':
                $content = '挑三拣四';
                // 日月水金火命主7宫主两个或两个以上落处女且有金海或月海；
                // 日月水金火命主7宫主四个或四个以上落处女
                $in_vir = 0;
                for($i = 0;$i<5;$i++) if($planets[$i]['in_sign_id'] == 6) $in_vir++;
                if($this->base_data['houses'][1]['in_sign_id'] == 6) $in_vir++;
                if($in_vir >= 4 || ($in_vir >=2 && (isset($planets[3]['phase']['3-8']) || isset($planets[1]['phase']['1-8']))))
                {
                    $content = '追求完美爱情';
                }
                break;
            case 'jingshenlianai':
                $content = '精神交流大于一切';
                if(isset($planets[3]['phase']['3-8']) || isset($planets[1]['phase']['1-8']))
                {
                    $nept_pk_inhouse7 = 0;
                    if(!empty($planets[9]['phase']))
                    {
                        foreach ($planets[9]['phase'] as $pk)
                        {
                            if($pk['id'] < 10 && $planets[$pk['id']]['in_house_id'] == 7) $nept_pk_inhouse7++;
                        }
                    }
                    if(in_array($planets[3]['in_house_id'],[1,7]) || $nept_pk_inhouse7 > 0)
                    {
                        if($planets[3]['in_house_id'] < 7)
                        {
                            $content = '爱上美好幻像';
                        }else{
                            $content = '跟自己的脑洞恋爱';
                        }
                    }
                }
                break;
            case 'cuoai':
                $content = '总碰不到对的人';
                // 火合刑冲或金海合刑冲或海王合下降
                if((isset($planets[4]['phase']['4-8']) && in_array($planets[4]['phase']['4-8']['phase_e'],[0,90,180]))
                    || (isset($planets[3]['phase']['3-8']) && in_array($planets[3]['phase']['3-8']['phase_e'],[0,90,180]))
                    || (isset($planets[8]['phase']['8-'.DES]) && $planets[8]['phase']['8-'.DES]['phase_e'] == 0))
                {
                    $content = '爱上不该爱的人';
                }
                break;
            case 'langman':
                $content = '风花雪月爱浪漫';
                break;
            case 'xisheng':
            case 'chenni':
                $content = '自我牺牲';
                if(session('userinfo.sex') == 2)
                {
                    $content = '爱到失去自我';
                }
                break;
            case 'qipian':
                $content = '面对谎言';
                if((isset($planets[8]['phase']['8-'.ASC]) && $planets[8]['phase']['8-'.ASC]['phase_e'] == 0)
                    || (isset($planets[8]['phase']['8-'.DES]) && $planets[8]['phase']['8-'.DES]['phase_e'] == 0))
                {
                    $content = '你骗我我骗你';
                }
                break;
            case 'fawei':
                $content = '单调乏味';
                break;
            case 'kongzhi':
                $content = '控制欲强烈';
                if(session('userinfo.sex') == 2)
                {
                    if(
                        (isset($planets[3]['phase']['3-6']) && isset($planets[3]['phase']['3-9'])
                            && (in_array($planets[1]['in_sign_id'],[8,10])
                                || isset($planets[1]['phase']['1-6']) || isset($planets[1]['phase']['1-9'])))
                        || (isset($planets[4]['phase']['4-6']) && isset($planets[4]['phase']['4-9'])
                            && ($planets[3]['in_sign_id'] == 8
                                || (isset($planets[3]['phase']['3-6']) && in_array($planets[3]['phase']['3-6']['phase_e'],[0,90,180]))
                                || (isset($planets[3]['phase']['3-9']) && in_array($planets[3]['phase']['3-9']['phase_e'],[0,90,180]))))
                    )
                    {
                        $content = '被囚禁的金丝雀';
                    }
                }
                break;
            case 'shenqing':
                $content = '用情至深';
                if(
                    isset($planets[3]['phase']['3-8']) || isset($planets[1]['phase']['1-8'])
                    || (((isset($planets[8]['phase']['8-'.ASC]) && $planets[8]['phase']['8-'.ASC]['phase_e'] == 0)
                        || (isset($planets[8]['phase']['8-'.DES]) && $planets[8]['phase']['8-'.DES]['phase_e'] == 0)))
                )
                {
                    $content = '情深深雨蒙蒙';
                }
                break;
            case 'zhanyouyu':
                $content = '渴望完全拥有';
                if(
                    ($planets[0]['in_sign_id'] %4 == 0 || $planets[1]['in_sign_id'] %4 == 0)
                    && (
                        (isset($planets[3]['phase']['3-6']) || isset($planets[3]['phase']['3-9']))
                        && (isset($planets[1]['phase']['1-6']) || isset($planets[1]['phase']['1-9']))
                        && (isset($planets[4]['phase']['4-6']) || isset($planets[4]['phase']['4-9']))
                    )
                )
                {
                    $content = '爱到窒息';
                }
                break;
            case 'jinji':
                $content = '伤痕深埋心底';
                if(
                    (in_array($planets[3]['in_house_id'],[8,12]) || isset($planets[3]['phase']['3-9']) || $planets[3]['in_sign_id'] == 8)
                    && (in_array($planets[1]['in_house_id'],[8,12]) || isset($planets[1]['phase']['1-9']) || $planets[1]['in_sign_id'] == 8)
                    && (in_array($planets[4]['in_house_id'],[8,12]) || isset($planets[4]['phase']['4-9']) || $planets[4]['in_sign_id'] == 8)
                )
                {
                    $content = '有些事不可言说';
                }
                break;
            case 'jiujie':
                $content = '分分合合';
                if(
                    $planets[0]['in_sign_id'] == 7 || $planets[1]['in_sign_id'] == 7 || $planets[2]['in_sign_id'] == 7
                    || $planets[3]['in_sign_id'] == 7 || $planets[4]['in_sign_id'] == 7 || $planets[ASC]['in_sign_id'] == 7
                )
                {
                    $content = '当断不断必受其乱';
                }
                break;
            case 'sanjiaolian':
                $content = '卷入三角关系';
                break;
            case 'zhengchao':
                $content = '吵吵更健康';
                if($planets[4]['in_sign_id']%4 == 0)
                {
                    $content = '床头吵架床尾合';
                }
                break;
            case 'zhudong':
                $content = '勇敢爱，勇敢恨';
                if($planets[4]['in_house_id'] % 4 == 1)
                {
                    $content = '爱就主动出击';
                }
                break;
            case 'kunhuo':
                $content = '迷路的爱情羔羊';
                if(
                    $planets[0]['in_sign_id'] == 7 || $planets[1]['in_sign_id'] == 7 || $planets[2]['in_sign_id'] == 7
                    || $planets[3]['in_sign_id'] == 7 || $planets[4]['in_sign_id'] == 7 || $planets[ASC]['in_sign_id'] == 7
                )
                {
                    $content = '爱让人不知所措';
                }
                break;
            case 'tianmi':
                $content = '甜蜜蜜';
                break;
            case 'xingxiyin':
                $content = '满满都是床戏';
                if($planets[3]['in_sign_id'] == 8)
                {
                    $content = '性魅力飞扬';
                }
                break;
            case 'jiqing':
                $content = '电力无限';
                if(
                    isset($planets[4]['phase']['4-5']) || $planets[4]['in_house_id'] % 4 == 1 || $planets[1]['in_house_id'] % 4 == 1
                )
                {
                    $content = '激情四射';
                }
                break;
            case 'shanhun':
                $content = '突然你就结婚了';
                break;
            case 'baoli':
                $content = '家庭暴力';
                if(
                    (isset($planets[1]['phase']['1-4']) && in_array($planets[1]['phase']['1-4']['phase_e'],[0,180]))
                    || $planets[1]['in_sign_id'] == 1 || isset($planets[4]['phase']['4-7'])
                )
                {
                    $content = '从床上打到床下';
                }
                break;
            case 'dushen':
                $content = '独身主义';
                $in_sign_7 = $in_sign_1 = $in_sign_11 = $in_house_5 = $in_house_7 = $p_pk_9 = 0;
                for ($i=0;$i<10;$i++)
                {
                    if($i < 5)
                    {
                        if($planets[$i]['in_sign_id'] == 7) $in_sign_7++;
                        if($planets[$i]['in_sign_id'] == 1) $in_sign_1++;
                        if($planets[$i]['in_sign_id'] == 11) $in_sign_11++;
                        if(isset($planets[$i]['phase'][$i.'-7'])) $p_pk_9++;
                    }
                    if($planets[$i]['in_house_id'] == 5) $in_house_5++;
                    if($planets[$i]['in_house_id'] == 7) $in_house_7++;
                }
                // 日月金水火升都不在天秤，且至少一个在白羊座或水瓶座，且天王独坐5或7宫；或，日月金水火，至少四个要么在水瓶座，要么与天王星成相
                if(
                    (($in_sign_7 == 0 && $planets[ASC]['in_sign_id'] != 7)
                        && ($in_sign_1 > 0 || $in_sign_11 > 0 || in_array($planets[ASC]['in_sign_id'],[1,11])) &&
                        (($in_house_5 == 1 && $planets[9]['in_house_id'] == 5) || ($in_house_7 == 1 && $planets[9]['in_house_id'] == 7)))
                    || ($in_sign_11 >= 4 || $p_pk_9 >= 4)

                )
                {
                    $content = '一个人过也挺好';
                }
                break;
            case 'yiguolian':
                $content = '那个人去了远方';
                // 日月金火至少三个(在射手或双鱼)或与木星成相，一个在水瓶座或与天王成相
                $in_sign_9 = $in_sign_11 = $in_sign_12 = $p_pk_5 = $p_pk_7 =  0;
                for($i=0;$i<5;$i++)
                {
                    if($i == 2) continue;
                    if($planets[$i]['in_sign_id'] == 9) $in_sign_9++;
                    if($planets[$i]['in_sign_id'] == 11) $in_sign_11++;
                    if($planets[$i]['in_sign_id'] == 12) $in_sign_12++;
                    if(isset($planets[$i]['phase'][$i.'-5'])) $p_pk_5++;
                    if(isset($planets[$i]['phase'][$i.'-7'])) $p_pk_7++;

                }
                if(
                    ($in_sign_9 >= 3 || $in_sign_12 >= 3 || $p_pk_5 >= 3) || ($in_sign_11 >= 1 || $p_pk_7 >= 1)
                )
                {
                    $content = '找个歪果仁伴侣';
                }
                break;
            case 'jiaoliu':
                $content = '注重交流';
                break;
            case 'rouqing':
                $content = '体贴照顾';
                break;
            case 'duobian':
                $content = '喜新厌旧';
                break;
            case 'laoshaopei':
                $content = '跨越年龄的结合';
                break;
            case 'yinren':
                $content = '忍到天荒地老';
                if(session('userinfo.sex') == 1)
                {
                    $content = '忍者神龟';
                }
                break;
            case 'tongxing':
                $content = '同性恋或性趣非凡';
                break;
            case 'lenggan':
                $content = '淡漠冷感';
                break;
            case 'fanchang':
                $content = '奇葩爱情一言难尽';
                break;
            case 'bumanzu':
                $content = '总觉得不被爱';
                if($planets[1]['in_house_id'] == 5 || $planets[3]['in_house_id'] == 5)
                {
                    $content = '渴望得到更多爱';
                }
                break;
            case 'chugui':
            case 'xingyinyou':
                $content = '禁不住性的诱惑';
                // 月金火都在双子、水瓶、双鱼、白羊之一
                if(
                    ($planets[1]['in_sign_id'] == 1 || $planets[1]['in_sign_id'] == 3
                        || $planets[1]['in_sign_id'] == 11 || $planets[1]['in_sign_id'] == 12)
                    && ($planets[3]['in_sign_id'] == 1 || $planets[3]['in_sign_id'] == 3
                        || $planets[3]['in_sign_id'] == 11 || $planets[3]['in_sign_id'] == 12)
                    && ($planets[4]['in_sign_id'] == 1 || $planets[4]['in_sign_id'] == 3
                        || $planets[4]['in_sign_id'] == 11 || $planets[4]['in_sign_id'] == 12)
                )
                {
                    $content = '出轨要偷偷的';
                }
                // 火星在8/12宫  与海王成相或落双鱼座
                elseif(in_array($planets[4]['in_house_id'],[8,12]) && ($planets[4]['in_sign_id'] == 12 || isset($planets[4]['phase']['4-8'])))
                {
                    $content = '偷尝禁果';
                }
                break;
            case 'siquhuolai':
                $content = '恨不能生死相许';
                if($planets[0]['in_sign_id'] % 4 == 0 || $planets[1]['in_sign_id'] % 4 == 0)
                {
                    $content = '爱一个死去活来';
                }
                break;
            case 'xiuenai':
                $content = '爱就秀给别人看';
                break;
            case 'beiju':
                $content = '我爱的人不爱我';
                // 金土刑克或金土本垣互容或金土本垣接纳   $this->base_data['characteristic'];
                $status = 0;
                foreach($this->base_data['characteristic'] as $d)
                {
                    if(($d['id1'] == 3 && $d['id2'] == 6) || ($d['id1'] == 6 && $d['id2'] == 3))
                    {
                        if($d['status'] == 1 && mb_substr($d['ancient2'],0,2,'utf-8') == '本垣')
                        {
                            $status = 1;
                        }
                        elseif($d['status'] == 2 && mb_substr($d['ancient1'],0,2,'utf-8') == '本垣'
                            && mb_substr($d['ancient2'],0,2,'utf-8') == '本垣')
                        {
                            $status = 1;
                        }
                    }
                }
                if(
                    (isset($planets[3]['phase']['3-6']) && in_array($planets[3]['phase']['3-6']['phase_e'],[90,180]))
                    || $status
                )
                {
                    $content = '爱上冷淡的人';
                }
                break;
            case 'jiduan':
                $content = '爱恨极端';
                $in_sign_8 = 0;
                $p_pk_9 = 0;
                for($i=0;$i<5;$i++)
                {
                    if($planets[$i]['in_sign_id'] == 8) $in_sign_8++;
                    if(isset($planets[$i]['phase'][$i.'-9'])) $p_pk_9++;
                }
                if($in_sign_8 >= 2 || $p_pk_9 >= 2)
                {
                    $content = '可怕的极端分子';
                }
                break;
            case 'qingxuduo':
                $content = '各种小情绪';
                if(
                    isset($planets[0]['phase']['0-4']) || isset($planets[1]['phase']['1-4']) || isset($planets[1]['phase']['1-5'])
                )
                {
                    $content = '控制不住闹情绪';
                }
                break;
        }
        return $content;
    }

    /**
     * 获取行星-行星关联度和冲突度
     * @param $pid int 行星id  如 金星3月亮1火星4
     * return array 关联度 冲突度
     */
    public function about_planet($pid = null)
    {
        $ret = ['relevancy'=>[],'conflict_degree'=>[]];
        if($pid === null) return $ret;
        $planet = $this->base_data['planets'][$pid];
        // 检查是否定位(是否入庙)  定位星+0.9
        // 当前行星定位其他行星   即当前行星的守护星座有哪些星体落在上面
        for($i = 0;$i<10;$i++)
        {
            if($i == $pid) continue;
            $i_in_sign_id = $this->base_data['planets'][$i]['in_sign_id'];
            $pro_id = config('astrolog.protect_id')[$i_in_sign_id-1];
            $pro_a_id = config('astrolog.protect_ancient_id')[$i_in_sign_id-1];
            if($pro_id == $pid || $pro_a_id == $pid)
            {
//                if ($pid ==7)echo "\$i=$i:\$pid=$pid,\$pro_id=$pro_id,\$pro_a_id=$pro_a_id\n";
                if(!isset($ret['relevancy'][$i])) $ret['relevancy'][$i] = 0.9;
                else $ret['relevancy'][$i] += 0.9;
            }
        }

        // 检查是否有互容 本垣互容  || 非本垣互容
        $ret = $this->get_planet_mutual_recept($pid,$ret);
        // 检查是否为唯一相位
        if(!empty($planet['phase']))
        {
            $phase_total = 0;
            foreach ($planet['phase'] as $k=> $phase)
            {
                if($phase['id'] < 10)
                {
                    $key = $phase['id'];
                    $phase_total++;
                }
            }
            // 唯一相位
            if($phase_total == 1)
            {
                if(!isset($ret['relevancy'][$key])) $ret['relevancy'][$key] = 1;
                else $ret['relevancy'][$key] += 1;
            }
            else
            {
                // 具体相位 0 60 90 120 180
                foreach ($planet['phase'] as $k => $phase)
                {
                    if($phase['id'] > 9) continue;
                    $temp = 0;
                    if($phase['phase_e'] == 0)
                    {
                        if($phase['phase_orb'] <= 1) $temp = 1;
                        elseif($phase['phase_orb'] <= 4) $temp = 0.95;
                        elseif($phase['phase_orb'] <= 7) $temp = 0.9;
                        else $temp = 0.85;
                    }
                    elseif($phase['phase_e'] == 60)
                    {
                        if($phase['phase_orb'] <= 1) $temp = 0.8;
                        elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                        elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                        else $temp = 0.65;
                    }
                    elseif($phase['phase_e'] == 120)
                    {
                        if($phase['phase_orb'] <= 1) $temp = 0.8;
                        elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                        elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                        else $temp = 0.65;
                    }
                    elseif($phase['phase_e'] == 90)
                    {
                        if($phase['phase_orb'] <= 1) $temp = 0.8;
                        elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                        elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                        else $temp = 0.65;
                        $ret['conflict_degree'][$phase['id']] = $temp * 2;
                    }
                    elseif($phase['phase_e'] == 180)
                    {
                        if($phase['phase_orb'] <= 1) $temp = 0.8;
                        elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                        elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                        else $temp = 0.65;
                        $ret['conflict_degree'][$phase['id']] = $temp * 2.5;
                    }

                    if(!isset($ret['relevancy'][$phase['id']]))
                    {
                        $ret['relevancy'][$phase['id']] = 0;
                    }
                    $ret['relevancy'][$phase['id']] += $temp;

                    if($phase['id'] == 0)
                    {
                        $ret['sun'] = $phase['phase_e'];
                    }
                }
            }
        }
        return $ret;
    }

    /**
     * 获取宫-星关联度和冲突度
     * @param null $hid 宫位id
     * @return array 关联度 冲突度
     */
    protected function about_house($hid = null)
    {
        $ret = ['relevancy'=>[],'conflict_degree'=>[]];
        $house = $this->base_data['houses'][$hid];
        // 判断宫内星或宫外星
        for($i=0;$i<10;$i++)
        {
            $planet = $this->base_data['planets'][$i];
            // 判断是否为宫主星 true 为宫主星 false 不是宫主星
            $is_house_protect = ($house['protect_id'] == $i || $house['protect_ancient_id'] == $i) ? true : false;
            $change = -10;// 关联度
            // 宫内星
            if($this->base_data['planets'][$i]['in_house_id'] == $hid)
            {
                // 与宫头不在同一星座
                if($house['in_sign_id'] != $planet['in_sign_id'])
                {
                    $change -= 0.3;
                }
                // 在宫头5度以内
                if(abs($planet['deg'] - $house['deg']) < 5 || abs(abs($planet['deg'] - $house['deg'])-360) < 5)
                {
                    $change += 0.2;
                }
                // 是宫主星 +1
                if($is_house_protect)
                {
                    $change += 1;
                }
                // 不是宫主星，但与宫主星关联度为w
                else
                {
                    $ph = $this->about_planet($i);
                    $w1 = isset($ph['relevancy'][$i . '-' .$house['protect_id']]) ?
                        $ph['relevancy'][$i . '-' .$house['protect_id']] : 0;
                    $w2 = isset($ph['relevancy'][$i . '-' .$house['protect_ancient_id']]) ?
                        $ph['relevancy'][$i . '-' .$house['protect_ancient_id']] : 0;
                    if($w1 >= $w2) $change += $w1;
                    elseif($w1 < $w2) $change += $w2;
                }
                if(!empty($planet['phase']))
                {
                    $phase_total = 0;
                    foreach ($planet['phase'] as $phase)
                    {
                        if($phase['id'] > 9) continue;
                        $phase_total++;
                    }
                }
                // 空相+0.4
                if(empty($planet['phase']) || $phase_total == 0)
                {
                    $change += 0.4;
                }
                // 庙旺状态
                if($planet['ancient']['walls'] == 1 || $planet['ancient']['promote'] == 1)
                {
                    $change += 0.1;
                }
                // 唯一宫内星 +0.4
                if($house['have_planet_num'] == 1 && $planet['in_house_id'] == $hid)
                {
                    $change += 0.4;
                }
            }
            if($change != -10)
            {
                $ret['relevancy'][$i] = 11 + $change;
            }
        }
        if(!isset($ret['relevancy'][$house['protect_id']]))
        {
            $ret['relevancy'][$house['protect_id']] = 1;
        }
        if(!isset($ret['relevancy'][$house['protect_ancient_id']]))
        {
            $ret['relevancy'][$house['protect_ancient_id']] = 1.2;
        }
        // 宫外星    （由于要用到宫内星与宫关联度   所以只能先把所有宫内星算完再计算宫外星的数据）
        for($i = 0;$i < 10 ;$i++)
        {
            $planet = $this->base_data['planets'][$i];

            // 宫外星
            if($planet['in_house_id'] != $hid)
            {

                foreach ($planet['phase'] as $phase)
                {
                    if($this->base_data['planets'][$phase['id']]['in_house_id'] == $hid
                        || $phase['id'] == $house['protect_id'] || $phase['id'] == $house['protect_ancient_id'])
                    {
                        $temp = 0;// 相位关联系数
                        $temp2 = 0;// 相位冲突系数
                        if($phase['phase_e'] == 0)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 1;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.95;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.9;
                            else $temp = 0.85;
                        }
                        elseif($phase['phase_e'] == 60)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 0.8;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                            else $temp = 0.65;
                        }
                        elseif($phase['phase_e'] == 120)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 0.8;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                            else $temp = 0.65;
                        }
                        elseif($phase['phase_e'] == 90)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 0.8;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                            else $temp = 0.65;
                            $temp2 = $temp * 2;
                        }
                        elseif($phase['phase_e'] == 180)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 0.8;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                            else $temp = 0.65;
                            $temp2 = $temp * 2.5;
                        }
//                        if($temp != 0)
//                        {
//                            if(!isset($ret['relevancy'][$i]))
//                            {
//                                $ret['relevancy'][$i] = $ret['relevancy'][$phase['id']] * $temp;
//                            }
//                            $ret['relevancy'][$i] += $ret['relevancy'][$phase['id']] * $temp;
//                        }
//                        if($temp2 != 0)
//                        {
//                            if(!isset($ret['conflict_degree'][$i]))
//                            {
//                                $ret['conflict_degree'][$i] = $ret['relevancy'][$phase['id']] * $temp2;
//                            }
//                            $ret['conflict_degree'][$i] += $ret['relevancy'][$phase['id']] * $temp2;
//                        }
                    }
                }

            }
        }
        return $ret;
    }

    /**
     * 获取宫-星关联度和冲突度
     * @param null $hid 宫位id
     * @return array 关联度 冲突度
     */
    protected function about_house1($hid = null)
    {
        $ret = ['relevancy'=>[],'conflict_degree'=>[]];
        if($hid === null) return $ret;
        $houses = $this->base_data['houses'][$hid];
        if($houses['have_planet_num'] != 0)
        {
            foreach ($houses['in_house_area_planet_info'] as $k => $hsp)
            {
                $ret['relevancy'][$hsp['id']] = 1;// 初始化宫内星关联度
                $planet = $this->base_data['planets'][$hsp['id']];
                // 与宫头不在同一星座
                if($houses['in_sign_id'] != $planet['in_sign_id'])
                {
                    $ret['relevancy'][$hsp['id']] += 1;
                }
                // 在宫头5度以内
                if($planet['deg'] - $houses['deg'] < 5)
                {
                    $ret['relevancy'][$hsp['id']] += 0.2;
                }
                // 是宫主星 +1
                if($hsp['id'] == $houses['protect_id'] || $hsp['id'] == $houses['protect_ancient_id'])
                {
                    $ret['relevancy'][$hsp['id']] += 1;
                }
                // 不是宫主星，但与宫主星关联度为w
                else
                {
                    $ph = $this->about_planet($hsp['id']);
                    $w1 = isset($ph['relevancy'][$hsp['id'] . '-' .$houses['protect_id']]) ?
                        $ph['relevancy'][$hsp['id'] . '-' .$houses['protect_id']] : 0;
                    $w2 = isset($ph['relevancy'][$hsp['id'] . '-' .$houses['protect_ancient_id']]) ?
                        $ph['relevancy'][$hsp['id'] . '-' .$houses['protect_ancient_id']] : 0;
                    if($w1 >= $w2) $ret['relevancy'][$hsp['id']] += $w1;
                    elseif($w1 < $w2) $ret['relevancy'][$hsp['id']] += $w2;
                }
                if(!empty($planet['phase']))
                {
                    $phase_total = 0;
                    foreach ($planet['phase'] as $i => $phase)
                    {
                        if($phase['id'] > 9) continue;
                        $phase_total++;
                    }
                }
                // 空相+0.4
                if(empty($planet['phase']) || $phase_total == 0)
                {
                    $ret['relevancy'][$hsp['id']] += 0.4;
                }
                // 庙旺状态
                if($planet['ancient']['walls'] == 1 || $planet['ancient']['promote'] == 1)
                {
                    $ret['relevancy'][$hsp['id']] += 0.1;
                }
            }
            // 唯一宫内星 +0.4
            if($houses['have_planet_num'] == 1)
            {
                $ret['relevancy'][$houses['in_house_area_planet_info'][0]['id']] += 0.4;
            }
        }
        // 宫主星古典占星体系
        if(!isset($ret['relevancy'][$houses['protect_id']]))
        {
            $ret['relevancy'][$houses['protect_id']] = 1.2;
        }
        // 宫主星三王
        if(!isset($ret['relevancy'][$houses['protect_ancient_id']]))
        {
            $ret['relevancy'][$houses['protect_ancient_id']] = 1;
        }
        // 与宫内或宫主星成相位
        // 等于成相位星体与宫位关联度*该相位关联系数
        // 等于成相位星体与宫位关联度*该相位冲突系数
        if($houses['have_planet_num'] > 0)
        {
            $temp3 = [];
            foreach($houses['in_house_area_planet_info'] as $k => $hsp)
            {
                $planets = $this->base_data['planets'][$hsp['id']];
                if(!empty($planets['phase']))
                {
                    foreach ($planets['phase'] as $i => $phase)
                    {
                        if($phase['id'] > 9) continue;
                        // 相位星关联度冲突度计算
                        $temp = 0;// 相位关联系数
                        $temp2 = 0;
                        if($phase['phase_e'] == 0)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 1;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.95;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.9;
                            else $temp = 0.85;
                        }
                        elseif($phase['phase_e'] == 60)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 0.8;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                            else $temp = 0.65;
                        }
                        elseif($phase['phase_e'] == 120)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 0.8;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                            else $temp = 0.65;
                        }
                        elseif($phase['phase_e'] == 90)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 0.8;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                            else $temp = 0.65;
                            $temp2 = $temp * 2;
//                            p($phase);
                            $temp3[$phase['phase_e'].'-'.$phase['id']][] = $temp2;
                        }
                        elseif($phase['phase_e'] == 180)
                        {
                            if($phase['phase_orb'] <= 1) $temp = 0.8;
                            elseif($phase['phase_orb'] <= 4) $temp = 0.75;
                            elseif($phase['phase_orb'] <= 7) $temp = 0.7;
                            else $temp = 0.65;
                            $temp2 = $temp * 2.5;
                            $temp3[$phase['phase_e'].'-'.$phase['id']][] = $temp2;
                        }
                        if(!isset($ret['relevancy'][$phase['id']]))
                        {
                            $ret['relevancy'][$phase['id']] = $ret['relevancy'][$hsp['id']] * $temp;
                        }
                        $ret['relevancy'][$phase['id']] += $ret['relevancy'][$hsp['id']] * $temp;

                        if(!isset($ret['conflict_degree'][$phase['id']]))
                        {
                            $ret['conflict_degree'][$phase['id']] = $ret['relevancy'][$hsp['id']] * $temp2;
                        }
                        $ret['conflict_degree'][$phase['id']] += $ret['relevancy'][$hsp['id']] * $temp2;
                    }
                }
            }
//            p($temp3);
        }
        return $ret;
    }


    /**
     * 计算合点行星
     * 合点计算 函数设计
     * 输入：某星盘上的一颗星X
     * 输出：与该星成相的合点个数及每个合点星系中的最大关联度
     * 1、相对于这颗星的位置，取出精确的对冲度数、合相度数、两个六分、两个四分、两个三分，一共8个合点度数；
     * 2、依次检测其它星体度数与这8个度数间的关系，是否在相应的容许度范围内，得到相对于8个合点的星体（有时一个合点会有多颗星体）；
     * 3、对于有星体的合点，各选择1个与X星关联系数最紧密的星体，作为输出
     */
    protected function get_conj_planet($pid = null,$asp_deg = null)
    {
        if($pid === null) return false;
        // 0°时  检测合相  合相视为同点
        if($asp_deg == 0)
        {

        }
        // 60° 检测成相方向 同向视为同点
        // 90° 检测成相方向 同向视为同点
        // 120° 检测成相方向 同向视为同点
        elseif($asp_deg == 60 || $asp_deg == 90 || $asp_deg == 120)
        {

        }
        // 180°时  检测成相星同时成180°的星   视为同点
        elseif($asp_deg == 180)
        {

        }
    }

    /**
     * 检查是否有互容 本垣互容  || 非本垣互容
     * @param null $pid
     * @return array
     */
    protected function get_planet_mutual_recept($pid = null,$ret = [])
    {
        $planets = $this->base_data['planets'];
        $p1 = $planets[$pid];
        for ($i = 0;$i < 10;$i++)
        {
            if($i == $pid) continue;
            $p2 = $planets[$i];
            $pid1 = $pid;
            $pid2 = $i;
            $insign1 = $p1['in_sign_id'];
            $insign2 = $p2['in_sign_id'];
            $insigndeg1 = $p1['in_sign_deg_e'];
            $insigndeg2 = $p2['in_sign_deg_e'];
            $ancient1 = $this->planet_in_ancient($pid1,$insign2,$insigndeg2);
            $ancient2 = $this->planet_in_ancient($pid2,$insign1,$insigndeg1);
            // 互容
            if($ancient1['power'] > 3 && $ancient2['power'] > 3)
            {
                if(!isset($ret['relevancy'][$pid2])) $ret['relevancy'][$pid2] = 0;
                if($ancient1['walls']==1 && $ancient2['walls']==1)
                {
                    $ret['relevancy'][$pid2] += 0.5;// 本垣互容
                }
                else
                {
                    $ret['relevancy'][$pid2] += 0.2;// 非本垣互容
                }
            }

        }
        return $ret;
    }

    /**
     * 计算行星  1入庙 或 2失势
     * @param null $p_id 行星ID
     * @param null $p_insign_id 行星落座id
     * @param string $p_insign_deg 行星落座度数
     * @return bool
     */
    protected function planet_in_ancient($p_id = null,$p_insign_id = null, $p_insign_deg = 0)
    {
        // 非古典七星落座位置也有该位置庙旺弱陷界十度信息
        if ($p_id === null || $p_id < 0 || $p_insign_id === null) return [];
        $ret = [
            'power'=> 0,
            'walls' => false,   'walls_cn' => '',// 庙
            'promote'=> false,  'promote_cn'=> '',// 旺
            'trisection'=>false,'trisection_cn'=>'',// 三分
            'extent'=>false,    'extent_cn'=>'',// 界
            'period'=>false,      'period_cn'=>'',// 面
            'migration' => false, 'migration_cn'=>'',// 游走
            'or_walls_planet_id'=>null,'or_promote_planet_id'=>null,
            'or_extent_planet_id'=>null,'or_period_planet_id'=>null,
            'or_trisection_planet_id'=>[],
        ];

        $fall = ($p_insign_id <= 6) ? ($p_insign_id + 6) : ($p_insign_id - 6);
        // 入庙
        if (config('astrolog.ancient')[$p_insign_id][0] == $p_id)
        {
            $ret['power'] += 5;
            $ret['walls']=1;
            $ret['walls_cn']='入庙';
        }
        elseif(config('astrolog.ancient')[$fall][0] == $p_id)
        {
            $ret['power'] -= 5;
            $ret['walls']=2;
            $ret['walls_cn']='失势';
        }

        $ret['or_walls_planet_id'] = config('astrolog.ancient')[$p_insign_id][0];
        $ret['or_walls_fall_planet_id'] = config('astrolog.ancient')[$fall][0];
        // 天王星  入庙 失势
        if($p_id == 7)
        {
            if($p_insign_id == 11)
            {
                $ret['power'] += 5;
                $ret['walls']=1;
                $ret['walls_cn']='入庙';
            }
            elseif($p_insign_id == 5)
            {
                $ret['power'] -= 5;
                $ret['walls']=2;
                $ret['walls_cn']='失势';
            }
            $ret['or_walls_planet_id'] = 11;
            $ret['or_walls_fall_planet_id'] = 5;
        }
        // 海王星  入庙 失势
        if($p_id == 8)
        {
            if($p_insign_id == 12)
            {
                $ret['power'] += 5;
                $ret['walls']=1;
                $ret['walls_cn']='入庙';
            }
            elseif($p_insign_id == 6)
            {
                $ret['power'] -= 5;
                $ret['walls']=2;
                $ret['walls_cn']='失势';
            }
            $ret['or_walls_planet_id'] = 12;
            $ret['or_walls_fall_planet_id'] = 6;
        }
        // 冥王星  入庙 失势
        if($p_id == 9)
        {
            if($p_insign_id == 8)
            {
                $ret['power'] += 5;
                $ret['walls']=1;
                $ret['walls_cn']='入庙';
            }
            elseif($p_insign_id == 2)
            {
                $ret['power'] -= 5;
                $ret['walls']=2;
                $ret['walls_cn']='失势';
            }
            $ret['or_walls_planet_id'] = 8;
            $ret['or_walls_fall_planet_id'] = 2;
        }
        // 擢升
        if (config('astrolog.ancient')[$p_insign_id][1] !== '' && config('astrolog.ancient')[$p_insign_id][1] == $p_id )
        {
            $ret['power'] += 4;
            $ret['promote']=1;
            $ret['promote_cn']='擢升';
        }
        elseif(config('astrolog.ancient')[$fall][1] !== '' && config('astrolog.ancient')[$fall][1] == $p_id)
        {
            $ret['power'] -= 4;
            $ret['promote']=2;
            $ret['promote_cn']='落陷';
        }
        $ret['or_promote_planet_id'] = config('astrolog.ancient')[$p_insign_id][1];
        $ret['or_promote_fall_planet_id'] = config('astrolog.ancient')[$fall][1];
        // 三分
        if (in_array($p_id, config('astrolog.ancient')[$p_insign_id][2]))
        {
            $ret['power'] += 3;
            $ret['trisection']=1;
            $ret['trisection_cn']='三分';
        }
        $ret['or_trisection_planet_id'] = config('astrolog.ancient')[$p_insign_id][2];
        // 界主 界主为1 +2
//        if (session('xzns.extent') == 'ptolemy_world')
//            $extent = config('astrolog.ancient')[$p_insign_id][3]['ptolemy_world'];
//        else
            $extent = config('astrolog.ancient')[$p_insign_id][3]['default'];

        for ($i = 0; $i < 5;$i++)
        {
            if ($p_insign_deg > $extent[1][$i] && $p_insign_deg < $extent[1][$i + 1])
            {
                if ($extent[0][$i] == $p_id)
                {
                    $ret['power'] += 2;
                    $ret['extent'] = 1;
                    $ret['extent_cn']='界主';
                }
                $ret['or_extent_planet_id'] = $extent[0][$i];
            }
        }
        // 旬主或十度
        for($i = 0; $i < 3;$i++)
        {
            $min = $i * 10;
            $max = $min + 10;
            if ($p_insign_deg > $min && $p_insign_deg < $max)
            {
                if (config('astrolog.ancient')[$p_insign_id][4][$i] == $p_id)
                {
                    $ret['power'] += 1;
                    $ret['period'] = 1;
                    $ret['period_cn']='旬主';
                }
                $ret['or_period_planet_id'] = config('astrolog.ancient')[$p_insign_id][4][$i];
            }
        }

        if(!$ret['walls'] && !$ret['promote'] && !$ret['trisection'] && !$ret['extent'] && !$ret['period'] && $ret['power'] == 0 && $p_id < 7)
        {
            $ret['power'] = -5;
            $ret['migration']=1;
            $ret['migration_cn']='游走';
        }
        if( $p_id > 6 && $p_id < 9 && $ret['walls'] == false )
        {
            $ret['power'] = -5;
            $ret['migration']=1;
            $ret['migration_cn']='游走';
        }

        return $ret;
    }

    protected function getLoveScore()
    {
        $venu = $this->base_data['planets'][3];
        $score = 500;
        #-----------------------------金星计算开始-----------------------------------#
        // 落6宫
        if($venu['in_house_id'] == 6)
        {
            $score *= 0.9;
        }
        // 落8宫
        elseif($venu['in_house_id'] == 8)
        {
            $score *= 0.8;
        }
        // 落12宫
        elseif($venu['in_house_id'] == 12)
        {
            $score *= 0.65;
        }
        // 落处女、天蝎、白羊座
        if(in_array($venu['in_sign_id'],[1,6,8]))
        {
            $score *= 0.85;
        }
        // 与月星成相
        if(isset($venu['phase']['3-1']) && ($venu['phase']['3-1']['phase_e'] == 90 || $venu['phase']['3-1']['phase_e'] == 180))
        {
            $score *= 0.7;
        }
        // 与火星成相
        if(isset($venu['phase']['3-4']))
        {
            if($venu['phase']['3-4']['phase_e'] == 90)
            {
                $score *= 0.7;
            }elseif($venu['phase']['3-4']['phase_e'] == 180)
            {
                $score *= 0.8;
            }
        }
        // 与木星成相
        if(isset($venu['phase']['3-5']))
        {
            if($venu['phase']['3-5']['phase_e'] == 90)
            {
                $score *= 0.85;
            }elseif($venu['phase']['3-5']['phase_e'] == 180)
            {
                $score *= 0.75;
            }
        }
        // 与土星成相
        if(isset($venu['phase']['3-6']))
        {
            if($venu['phase']['3-6']['phase_e'] == 90)
            {
                $score *= 0.7;
            }
            elseif($venu['phase']['3-6']['phase_e'] == 180)
            {
                $score *= 0.65;
            }
            elseif($venu['phase']['3-6']['phase_e'] == 0)
            {
                $score *= 0.7;
            }
        }
        // 与天、海、冥四分
        if((isset($venu['phase']['3-7']) && $venu['phase']['3-7']['phase_e'] == 90)
            || (isset($venu['phase']['3-8']) && $venu['phase']['3-8']['phase_e'] == 90)
            || (isset($venu['phase']['3-9']) && $venu['phase']['3-9']['phase_e'] == 90))
        {
            $score *= 0.65;
        }
        // 与天、海、冥对分
        if((isset($venu['phase']['3-7']) && $venu['phase']['3-7']['phase_e'] == 180)
            || (isset($venu['phase']['3-8']) && $venu['phase']['3-8']['phase_e'] == 180)
            || (isset($venu['phase']['3-9']) && $venu['phase']['3-9']['phase_e'] == 180))
        {
            $score *= 0.6;
        }
        // 与天、海、冥合相
        if((isset($venu['phase']['3-7']) && $venu['phase']['3-7']['phase_e'] == 0)
            || (isset($venu['phase']['3-8']) && $venu['phase']['3-8']['phase_e'] == 0)
            || (isset($venu['phase']['3-9']) && $venu['phase']['3-9']['phase_e'] == 0))
        {
            $score *= 0.7;
        }
        // 计算金星成相数量 只计算日月水金火木土天海冥
        $venu_phase_total = 0;
        if(!empty($venu['phase']))
        {
            foreach ($venu['phase'] as $v)
            {
                if($v['id'] < 10)
                {
                    $venu_phase_total++;
                }
            }
        }
        // 独与天海冥成相
        if($venu_phase_total == 1)
        {
            if(isset($venu['phase']['3-7']) || isset($venu['phase']['3-8']) || isset($venu['phase']['3-9']))
            {
                $score *= 0.85;
            }
        }
        // 落T三角顶点
        foreach ($this->base_data['structure']['t_square'] as $square)
        {
            if($square['top'] == 3) $score *= 0.8;
        }
        #-----------------------------金星计算结束-----------------------------------#




        #-----------------------------7宫主计算开始-----------------------------------#
        $house7 = $this->base_data['houses'][7];
        $house7_protect = $this->base_data['planets'][$this->base_data['houses'][7]['protect_ancient_id']];
        // 落6宫
        if($house7_protect['in_house_id'] == 6)
        {
            $score *= 0.75;
        }
        // 落8宫
        elseif($house7_protect['in_house_id'] == 8)
        {
            $score *= 0.8;
        }
        // 落12宫
        elseif($house7_protect['in_house_id'] == 12)
        {
            $score *= 0.65;
        }
        // 7宫主失势或落陷
        if($house7_protect['ancient']['walls'] == 2 || $house7_protect['ancient']['promote'] == 2)
        {
            $score *= 0.9;
        }
        // 与太阳四分或对分
        if(isset($house7_protect['phase'][$house7_protect['id'] . '-0']))
        {
            if($house7_protect['phase'][$house7_protect['id'] . '-0']['phase_e'] == 90
                || $house7_protect['phase'][$house7_protect['id'] . '-0']['phase_e'] == 180)
            {
                // 火土时
                if($house7_protect['id'] == 4 || $house7_protect['id'] == 6)
                {
                    $score *= 0.8;
                }
                // 月木
                elseif($house7_protect['id'] == 1 || $house7_protect['id'] == 5)
                {
                    $score *= 0.9;
                }
            }
        }
        // 与月亮四分或对分
        if(isset($house7_protect['phase'][$house7_protect['id'] . '-1']))
        {
            if($house7_protect['phase'][$house7_protect['id'] . '-1']['phase_e'] == 90
                || $house7_protect['phase'][$house7_protect['id'] . '-1']['phase_e'] == 180)
            {
                // 火土
                if($house7_protect['id'] == 4 || $house7_protect['id'] == 6)
                {
                    $score *= 0.7;
                }
                // 日金水木
                elseif($house7_protect['id'] == 0 || $house7_protect['id'] == 2 || $house7_protect['id'] == 3 || $house7_protect['id'] == 5)
                {
                    $score *= 0.85;
                }
            }
        }
        // 与火星四分、合或对分
        if(isset($house7_protect['phase'][$house7_protect['id'] . '-4']))
        {
            // 四分、合
            if($house7_protect['phase'][$house7_protect['id'] . '-4']['phase_e'] == 90
                || $house7_protect['phase'][$house7_protect['id'] . '-4']['phase_e'] == 0)
            {
                $score *= 0.8;
            }
            // 对分
            elseif($house7_protect['phase'][$house7_protect['id'] . '-4']['phase_e'] == 180)
            {
                $score *= 0.7;
            }
        }
        // 与木星四分或对分
        if(isset($house7_protect['phase'][$house7_protect['id'] . '-5']))
        {
            // 四分
            if($house7_protect['phase'][$house7_protect['id'] . '-5']['phase_e'] == 90)
            {
                $score *= 0.9;
            }
            // 对分
            elseif($house7_protect['phase'][$house7_protect['id'] . '-5']['phase_e'] == 180)
            {
                $score *= 0.85;
            }
        }
        // 与土星四分、合或对分
        if(isset($house7_protect['phase'][$house7_protect['id'] . '-6']))
        {
            // 四分、合
            if($house7_protect['phase'][$house7_protect['id'] . '-6']['phase_e'] == 90
                || $house7_protect['phase'][$house7_protect['id'] . '-6']['phase_e'] == 0)
            {
                $score *= 0.8;
            }
            // 对分
            elseif($house7_protect['phase'][$house7_protect['id'] . '-6']['phase_e'] == 180)
            {
                $score *= 0.7;
            }
        }
        // 与天、海、冥四分
        if((isset($house7_protect['phase'][$house7_protect['id'] . '-7']) && $house7_protect['phase'][$house7_protect['id'] . '-7']['phase_e'] == 90)
            || (isset($house7_protect['phase'][$house7_protect['id'] . '-8']) && $house7_protect['phase'][$house7_protect['id'] . '-8']['phase_e'] == 90)
            || (isset($house7_protect['phase'][$house7_protect['id'] . '-9']) && $house7_protect['phase'][$house7_protect['id'] . '-9']['phase_e'] == 90))
        {
            $score *= 0.75;
        }
        // 与天、海、冥对分
        if((isset($house7_protect['phase'][$house7_protect['id'] . '-7']) && $house7_protect['phase'][$house7_protect['id'] . '-7']['phase_e'] == 180)
            || (isset($house7_protect['phase'][$house7_protect['id'] . '-8']) && $house7_protect['phase'][$house7_protect['id'] . '-8']['phase_e'] == 180)
            || (isset($house7_protect['phase'][$house7_protect['id'] . '-9']) && $house7_protect['phase'][$house7_protect['id'] . '-9']['phase_e'] == 180))
        {
            $score *= 0.65;
        }
        // 与天、海、冥合相
        if((isset($house7_protect['phase'][$house7_protect['id'] . '-7']) && $house7_protect['phase'][$house7_protect['id'] . '-7']['phase_e'] == 0)
            || (isset($house7_protect['phase'][$house7_protect['id'] . '-8']) && $house7_protect['phase'][$house7_protect['id'] . '-8']['phase_e'] == 0)
            || (isset($house7_protect['phase'][$house7_protect['id'] . '-9']) && $house7_protect['phase'][$house7_protect['id'] . '-9']['phase_e'] == 0))
        {
            $score *= 0.75;
        }
        // 落T三角顶点
        foreach ($this->base_data['structure']['t_square'] as $square)
        {
            if($square['top'] == $house7_protect['id']) $score *= 0.8;
        }
        #-----------------------------7宫主计算结束-----------------------------------#




        #-----------------------------7宫内计算开始-----------------------------------#
        $in_house7 = $this->base_data['houses'][7]['in_house_area_planet_info'];
        $in_house_total = 0;
        if(!empty($in_house7))
        {
            foreach ($in_house7 as $k => $pl)
            {
                $pid = $pl['id'];
                if($pid < 10) $in_house_total++;
                if($pid == 7)
                {
                    $score *= 0.75;
                }
                elseif($pid == 8)
                {
                    $score *= 0.7;
                }
                elseif($pid == 9)
                {
                    $score *= 0.75;
                }
                else
                {
                    $ancient = $this->base_data['planets'][$pid]['ancient'];
                    $change = 1;
                    if($ancient['walls'] == 2 || $ancient['promote'] == 2)
                    {
                        if($pid == 0) $change = 0.95;
                        elseif ($pid == 1) $change = 0.85;
                        elseif ($pid == 2) $change = 0.85;
                        elseif ($pid == 3) $change = 0.9;
                        elseif ($pid == 4) $change = 0.7;
                        elseif ($pid == 5) $change = 0.85;
                        elseif ($pid == 6) $change = 0.7;
                    }
                    else
                    {
                        if($pid == 0) $change = 1.2;
                        elseif ($pid == 1) $change = 0.95;
                        elseif ($pid == 2) $change = 0.9;
                        elseif ($pid == 3) $change = 1.2;
                        elseif ($pid == 4) $change = 0.8;
                        elseif ($pid == 5) $change = 0.9;
                        elseif ($pid == 6) $change = 0.75;
                    }
                    $score *= $change;
                }
                $in_house7_phase = $this->base_data['planets'][$pid]['phase'];
                if(!empty($in_house7_phase))
                {
                    if((isset($in_house7_phase[$pid.'-7']) && $in_house7_phase[$pid.'-7']['phase_e'] == 180)
                        || (isset($in_house7_phase[$pid.'-8']) && $in_house7_phase[$pid.'-8']['phase_e'] == 180)
                        || (isset($in_house7_phase[$pid.'-9']) && $in_house7_phase[$pid.'-9']['phase_e'] == 180))
                    {
                        $score *= 0.6;
                    }
                    if((isset($in_house7_phase[$pid.'-7']) && $in_house7_phase[$pid.'-7']['phase_e'] == 90)
                        || (isset($in_house7_phase[$pid.'-8']) && $in_house7_phase[$pid.'-8']['phase_e'] == 90)
                        || (isset($in_house7_phase[$pid.'-9']) && $in_house7_phase[$pid.'-9']['phase_e'] == 90))
                    {
                        $score *= 0.7;
                    }
                    if((isset($in_house7_phase[$pid.'-4']) && $in_house7_phase[$pid.'-4']['phase_e'] == 180)
                        || (isset($in_house7_phase[$pid.'-6']) && $in_house7_phase[$pid.'-6']['phase_e'] == 180))
                    {
                        $score *= 0.7;
                    }
                    if((isset($in_house7_phase[$pid.'-4']) && $in_house7_phase[$pid.'-4']['phase_e'] == 90)
                        || (isset($in_house7_phase[$pid.'-6']) && $in_house7_phase[$pid.'-6']['phase_e'] == 90))
                    {
                        $score *= 0.75;
                    }
                    if(isset($in_house7_phase[$pid.'-1']))
                    {
                        if($in_house7_phase[$pid.'-1']['phase_e'] == 90 || $in_house7_phase[$pid.'-1']['phase_e'] == 180)
                        {
                            $score *= 0.75;
                        }
                    }
                    if((isset($in_house7_phase[$pid.'-0']) &&
                            ($in_house7_phase[$pid.'-0']['phase_e'] == 90
                                || $in_house7_phase[$pid.'-0']['phase_e'] == 180))
                        || (isset($in_house7_phase[$pid.'-2']) &&
                            ($in_house7_phase[$pid.'-2']['phase_e'] == 90
                                || $in_house7_phase[$pid.'-2']['phase_e'] == 180))
                        || (isset($in_house7_phase[$pid.'-3']) &&
                            ($in_house7_phase[$pid.'-3']['phase_e'] == 90
                                || $in_house7_phase[$pid.'-3']['phase_e'] == 180))
                        || (isset($in_house7_phase[$pid.'-5']) &&
                            ($in_house7_phase[$pid.'-5']['phase_e'] == 90
                                || $in_house7_phase[$pid.'-5']['phase_e'] == 180)))
                    {
                        $score *= 0.8;
                    }
                }

            }
            // 落三颗星或以上
            if($in_house_total >= 3)
            {
                $score *= 0.7;
            }
        }
        #-----------------------------7宫内计算结束-----------------------------------#




        #-----------------------------5宫主计算开始-----------------------------------#
        $house5 = $this->base_data['houses'][5];
        $house5_protect = $this->base_data['planets'][$house5['protect_ancient_id']];
        // 落6宫
        if($house5_protect['in_house_id'] == 6)
        {
            $score *= 0.9;
        }
        // 落8宫
        elseif($house5_protect['in_house_id'] == 8)
        {
            $score *= 0.8;
        }
        // 落12宫
        elseif($house5_protect['in_house_id'] == 12)
        {
            $score *= 0.7;
        }
        // 5宫主失势或落陷
        if($house5_protect['ancient']['walls'] == 2 || $house5_protect['ancient']['promote'] == 2)
        {
            $score *= 0.9;
        }
        // 与太阳四分或对分
        if(isset($house5_protect['phase'][$house5_protect['id'] . '-0']))
        {
            if($house5_protect['phase'][$house5_protect['id'] . '-0']['phase_e'] == 90
                || $house5_protect['phase'][$house5_protect['id'] . '-0']['phase_e'] == 180)
            {
                // 火土时
                if($house5_protect['id'] == 4 || $house5_protect['id'] == 6)
                {
                    $score *= 0.8;
                }
                // 月木
                elseif($house5_protect['id'] == 1 || $house5_protect['id'] == 5)
                {
                    $score *= 0.9;
                }
            }
        }
        // 与月亮四分或对分
        if(isset($house5_protect['phase'][$house5_protect['id'] . '-1']))
        {
            if($house5_protect['phase'][$house5_protect['id'] . '-1']['phase_e'] == 90
                || $house5_protect['phase'][$house5_protect['id'] . '-1']['phase_e'] == 180)
            {
                // 火土
                if($house5_protect['id'] == 4 || $house5_protect['id'] == 6)
                {
                    $score *= 0.7;
                }
                // 日金水木
                elseif($house5_protect['id'] == 0 || $house5_protect['id'] == 2 || $house5_protect['id'] == 3 || $house5_protect['id'] == 5)
                {
                    $score *= 0.85;
                }
            }
        }
        // 与火星四分、合或对分
        if(isset($house5_protect['phase'][$house5_protect['id'] . '-4']))
        {
            // 四分、合
            if($house5_protect['phase'][$house5_protect['id'] . '-4']['phase_e'] == 90
                || $house5_protect['phase'][$house5_protect['id'] . '-4']['phase_e'] == 0)
            {
                $score *= 0.85;
            }
            // 对分
            elseif($house5_protect['phase'][$house5_protect['id'] . '-4']['phase_e'] == 180)
            {
                $score *= 0.7;
            }
        }
        // 与木星四分或对分
        if(isset($house5_protect['phase'][$house5_protect['id'] . '-5']))
        {
            // 四分
            if($house5_protect['phase'][$house5_protect['id'] . '-5']['phase_e'] == 90)
            {
                $score *= 0.9;
            }
            // 对分
            elseif($house5_protect['phase'][$house5_protect['id'] . '-5']['phase_e'] == 180)
            {
                $score *= 0.85;
            }
        }
        // 与土星四分、合或对分
        if(isset($house5_protect['phase'][$house5_protect['id'] . '-6']))
        {
            // 四分、合
            if($house5_protect['phase'][$house5_protect['id'] . '-6']['phase_e'] == 90
                || $house5_protect['phase'][$house5_protect['id'] . '-6']['phase_e'] == 0)
            {
                $score *= 0.8;
            }
            // 对分
            elseif($house5_protect['phase'][$house5_protect['id'] . '-6']['phase_e'] == 180)
            {
                $score *= 0.7;
            }
        }
        // 与天、海、冥四分
        if((isset($house5_protect['phase'][$house5_protect['id'] . '-7']) && $house5_protect['phase'][$house5_protect['id'] . '-7']['phase_e'] == 90)
            || (isset($house5_protect['phase'][$house5_protect['id'] . '-8']) && $house5_protect['phase'][$house5_protect['id'] . '-8']['phase_e'] == 90)
            || (isset($house5_protect['phase'][$house5_protect['id'] . '-9']) && $house5_protect['phase'][$house5_protect['id'] . '-9']['phase_e'] == 90))
        {
            $score *= 0.75;
        }
        // 与天、海、冥对分
        if((isset($house5_protect['phase'][$house5_protect['id'] . '-7']) && $house5_protect['phase'][$house5_protect['id'] . '-7']['phase_e'] == 180)
            || (isset($house5_protect['phase'][$house5_protect['id'] . '-8']) && $house5_protect['phase'][$house5_protect['id'] . '-8']['phase_e'] == 180)
            || (isset($house5_protect['phase'][$house5_protect['id'] . '-9']) && $house5_protect['phase'][$house5_protect['id'] . '-9']['phase_e'] == 180))
        {
            $score *= 0.65;
        }
        // 与天、海、冥合相
        if((isset($house5_protect['phase'][$house5_protect['id'] . '-7']) && $house5_protect['phase'][$house5_protect['id'] . '-7']['phase_e'] == 0)
            || (isset($house5_protect['phase'][$house5_protect['id'] . '-8']) && $house5_protect['phase'][$house5_protect['id'] . '-8']['phase_e'] == 0)
            || (isset($house5_protect['phase'][$house5_protect['id'] . '-9']) && $house5_protect['phase'][$house5_protect['id'] . '-9']['phase_e'] == 0))
        {
            $score *= 0.75;
        }
        // 落T三角顶点
        foreach ($this->base_data['structure']['t_square'] as $square)
        {
            if($square['top'] == $house5_protect['id']) $score *= 0.8;
        }
        #-----------------------------5宫主计算结束-----------------------------------#




        #-----------------------------5宫内计算开始-----------------------------------#
        $in_house5 = $this->base_data['houses'][7]['in_house_area_planet_info'];
        $in_house5_total = 0;
        if(!empty($in_house5))
        {
            foreach ($in_house5 as $k => $pl)
            {
                $pid = $pl['id'];
                if($pid < 10) $in_house5_total++;
                if($pid == 7)
                {
                    $score *= 0.75;
                }
                elseif($pid == 8)
                {
                    $score *= 0.7;
                }
                elseif($pid == 9)
                {
                    $score *= 0.75;
                }
                else
                {
                    $ancient = $this->base_data['planets'][$pid]['ancient'];
                    $change = 1;
                    if($ancient['walls'] == 2 || $ancient['promote'] == 2)
                    {
                        if($pid == 0) $change = 0.95;
                        elseif ($pid == 1) $change = 0.85;
                        elseif ($pid == 2) $change = 0.85;
                        elseif ($pid == 3) $change = 0.9;
                        elseif ($pid == 4) $change = 0.7;
                        elseif ($pid == 5) $change = 0.85;
                        elseif ($pid == 6) $change = 0.7;
                    }
                    else
                    {
                        if($pid == 0) $change = 1.1;
                        elseif ($pid == 1) $change = 0.85;
                        elseif ($pid == 2) $change = 0.95;
                        elseif ($pid == 3) $change = 1.2;
                        elseif ($pid == 4) $change = 0.8;
                        elseif ($pid == 5) $change = 1.1;
                        elseif ($pid == 6) $change = 0.75;
                    }
                    $score *= $change;
                }
                $in_house5_phase = $this->base_data['planets'][$pid]['phase'];
                if(!empty($in_house5_phase))
                {
                    if((isset($in_house5_phase[$pid.'-7']) && $in_house5_phase[$pid.'-7']['phase_e'] == 180)
                        || (isset($in_house5_phase[$pid.'-8']) && $in_house5_phase[$pid.'-8']['phase_e'] == 180)
                        || (isset($in_house5_phase[$pid.'-9']) && $in_house5_phase[$pid.'-9']['phase_e'] == 180))
                    {
                        $score *= 0.7;
                    }
                    if((isset($in_house5_phase[$pid.'-7']) && $in_house5_phase[$pid.'-7']['phase_e'] == 90)
                        || (isset($in_house5_phase[$pid.'-8']) && $in_house5_phase[$pid.'-8']['phase_e'] == 90)
                        || (isset($in_house5_phase[$pid.'-9']) && $in_house5_phase[$pid.'-9']['phase_e'] == 90))
                    {
                        $score *= 0.7;
                    }
                    if((isset($in_house5_phase[$pid.'-4']) && $in_house5_phase[$pid.'-4']['phase_e'] == 180)
                        || (isset($in_house5_phase[$pid.'-6']) && $in_house5_phase[$pid.'-6']['phase_e'] == 180))
                    {
                        $score *= 0.7;
                    }
                    if((isset($in_house5_phase[$pid.'-4']) && $in_house5_phase[$pid.'-4']['phase_e'] == 90)
                        || (isset($in_house5_phase[$pid.'-6']) && $in_house5_phase[$pid.'-6']['phase_e'] == 90))
                    {
                        $score *= 0.75;
                    }
                    if(isset($in_house5_phase[$pid.'-1']))
                    {
                        if($in_house5_phase[$pid.'-1']['phase_e'] == 90 || $in_house5_phase[$pid.'-1']['phase_e'] == 180)
                        {
                            $score *= 0.75;
                        }
                    }
                    if((isset($in_house5_phase[$pid.'-0']) &&
                            ($in_house5_phase[$pid.'-0']['phase_e'] == 90
                                || $in_house5_phase[$pid.'-0']['phase_e'] == 180))
                        || (isset($in_house5_phase[$pid.'-2']) &&
                            ($in_house5_phase[$pid.'-2']['phase_e'] == 90
                                || $in_house5_phase[$pid.'-2']['phase_e'] == 180))
                        || (isset($in_house5_phase[$pid.'-3']) &&
                            ($in_house5_phase[$pid.'-3']['phase_e'] == 90
                                || $in_house5_phase[$pid.'-3']['phase_e'] == 180))
                        || (isset($in_house5_phase[$pid.'-5']) &&
                            ($in_house5_phase[$pid.'-5']['phase_e'] == 90
                                || $in_house5_phase[$pid.'-5']['phase_e'] == 180)))
                    {
                        $score *= 0.8;
                    }
                }

            }
            // 落三颗星或以上
            if($in_house5_total >= 3)
            {
                $score *= 0.75;
            }
        }
        #-----------------------------5宫内计算结束-----------------------------------#





        #-----------------------------火星计算开始-----------------------------------#
        $fire = $this->base_data['planets'][4];
        // 落6宫
        if($fire['in_house_id'] == 6)
        {
            $score *= 0.9;
        }
        // 落8宫
        elseif($fire['in_house_id'] == 8)
        {
            $score *= 0.8;
        }
        // 落12宫
        elseif($fire['in_house_id'] == 12)
        {
            $score *= 0.65;
        }
        // 落天秤、巨蟹、金牛
        if(in_array($fire['in_sign_id'],[2,4,7]))
        {
            $score *= 0.85;
        }elseif(in_array($fire['in_sign_id'],[11,12]))
        {
            $score *= 0.9;
        }
        // 与土星成相
        if(isset($fire['phase']['4-6']))
        {
            if($fire['phase']['4-6']['phase_e'] == 0 || $fire['phase']['4-6']['phase_e'] == 90 || $fire['phase']['4-6']['phase_e'] == 180)
            {
                $score *= 0.8;
            }
        }
        // 与天王星成相
        if(isset($fire['phase']['4-7']))
        {
            if($fire['phase']['4-7']['phase_e'] == 0 || $fire['phase']['4-7']['phase_e'] == 90 || $fire['phase']['4-7']['phase_e'] == 180)
            {
                $score *= 0.75;
            }
        }
        // 与海王星成相
        if(isset($fire['phase']['4-8']))
        {
            if($fire['phase']['4-8']['phase_e'] == 0 || $fire['phase']['4-8']['phase_e'] == 90 || $fire['phase']['4-8']['phase_e'] == 180)
            {
                $score *= 0.7;
            }
        }

        #-----------------------------火星计算结束-----------------------------------#
//        p($this->base_data['houses'][7]);
//        p($this->base_data['houses'][5]);
//        p($this->base_data['planets'][4]);
//        p($score);
        return $score;
    }




}
